- templates are [vinyl][] files
- rich plugin support, use any [base][] plugin!
- render templates with any template engine, including [nunjucks][engine-nunjucks], [handlebars][engine-handlebars], [lodash][engine-lodash] and any consolidate engine!
- helpers: support for sync and async
- templates collections support
- partials and includes
- layouts
- pages
- custom template "types"
- pagination
- [permalinks][assemble-permalinks]
- middleware can be used to tranform files at any stage in the render cycle
- pagination
- Much more!
var templates = require('{%= name %}');
var app = templates();
// register an engine to automatically render `md` files
app.engine('md', require('engine-lodash'));
// create a template collection
app.create('pages');
// add a template to the collection
app.page('post.md', {content: 'This is the <%= title %> page'});
// render it
app.render('post.md', {title: 'Home'}, function(err, view) {
console.log(view.content);
//=> 'This is the Home page'
});
This section describes API features that are shared by all Templates classes.
Set or get an option value.
Params
key
{String|Object}: Pass a key-value pair or an object to set.val
{any}: Any value when a key-value pair is passed. This can also be options if a glob pattern is passed as the first value.returns
{Object}: Returns the instance for chaining.
Example
app.option('a', 'b');
app.option({c: 'd'});
console.log(app.options);
//=> {a: 'b', c: 'd'}
Run a plugin on the given instance. Plugins are invoked immediately upon instantiating in the order in which they were defined.
Example
The simplest plugin looks something like the following:
app.use(function(inst) {
// do something to `inst`
});
Note that inst
is the instance of the class you're instantiating. So if you create an instance of Collection
, inst is the collection instance.
Params
fn
{Function}: Plugin function. If the plugin returns a function it will be passed to theuse
method of each item created on the instance.returns
{Object}: Returns the instance for chaining.
Usage
collection.use(function(items) {
// `items` is the instance, as is `this`
// optionally return a function to be passed to
// the `.use` method of each item created on the
// instance
return function(item) {
// do stuff to each `item`
};
});
The Templates
class is the main export of the templates
library. All of the other classes are exposed as static properties on Templates
:
- Item: Collection item, powered by [vinyl-item][].
- View: Collection item, powered by [vinyl-view][].
- List
- Views:
- Collection: Base collections class. Use this if you need to customize the render cycle, middleware stages, and so on.
- Group
{%= apidocs("index.js", {appname: 'app', ctor: 'templates'}) %}
{%= apidocs("node_modules/base-engines/index.js") %}
{%= apidocs("node_modules/base-helpers/index.js", {appname: 'app'}) %}
{%= apidocs("lib/helpers.js", {appname: 'app'}) %}
API for the View
class.
{%= apidocs("node_modules/vinyl-view/index.js") %}
{%= apidocs("lib/plugins/context.js", {appname: 'view'}) %}
API for the Item
class.
{%= apidocs("node_modules/vinyl-item/index.js") %}
{%= apidocs("lib/plugins/context.js", {appname: 'item'}) %}
API for the Views
class.
{%= apidocs("lib/views.js") %}
{%= apidocs("lib/plugins/context.js", {appname: 'views'}) %}
{%= apidocs("lib/plugins/lookup.js") %}
API for the Collections
class.
{%= apidocs("lib/collection.js") %} {%= apidocs("lib/plugins/context.js", {appname: 'collection'}) %}
API for the List
class.
{%= apidocs("lib/list.js") %} {%= apidocs("lib/plugins/context.js", {appname: 'list'}) %}
API for the Group
class.
{%= apidocs("lib/group.js") %}
{%= apidocs("lib/plugins/lookup.js") %}
{%= apidocs("lib/plugins/render.js") %}
{%= apidocs("lib/plugins/context.js", {appname: 'app'}) %}
Control the entire render cycle, with simple-to-use routes and middleware.
{%= apidocs("node_modules/base-routes/index.js") %}
{%= apidocs("lib/plugins/is.js") %}
This is just a very basic glimpse at the templates
API!
var templates = require('templates');
var app = templates();
// create a collection
app.create('pages');
// add views to the collection
app.page('a.html', {content: 'this is <%= foo %>'});
app.page('b.html', {content: 'this is <%= bar %>'});
app.page('c.html', {content: 'this is <%= baz %>'});
app.pages.getView('a.html')
.render({foo: 'home'}, function (err, view) {
//=> 'this is home'
});
{%= changelog('changelog.md') %}