Skip to content
This repository has been archived by the owner on Mar 20, 2018. It is now read-only.
Matt Hinchliffe edited this page Sep 26, 2013 · 3 revisions

Data can be provided globally to templates (layouts, partials and pages) via data files. Data files can be provided in JSON or YAML formats or as a JavaScript module. Robot is able to scan nested directories and will only attempt to register files with the following file extensions:- .json, .yml, .yaml and .js.

Please note that currently directory structure has no affect and all data is available at a single level.

Examples

~/robot-project/data/users/john-doe.json:

{
	"firstName": "John",
	"lastName": "Doe",
	"age": 28,
	"email": "john.doe@example.com"
}

~/robot-project/data/pets.js:

module.exports.pets = {
	rover: {
		age: 7,
		type: "dog",
		gender: "male"
	},
	mittens: {
		age: 3,
		type: "rabbit",
		gender: "female"
	}
};

module.exports.typesOfPets = function() {
	var uniqueTypes = [];

	for (var pet in this.pets) {
		if (this.pets.hasOwnProperty(pet) && uniqueTypes.indexOf(this.pets[pet]['type']) === -1) {
			types.push(this.pets[pet]['type']);
		}
	}

	return uniqueTypes;
};

Using Robot: Next: Partials

Clone this wiki locally