-
Notifications
You must be signed in to change notification settings - Fork 18
Templating
...
...
In order to include partial based on data the handlebars helper dynamicPartial can be used. please follow the examples on this page: Handlebars Page
data is passed either by the global data object, by providing an object or by passing it directly as options in the include tag. by default the current context is passed down the the partial, you replace id by passing another context-object).
Object: {{> "modules/mymodule/mymodule" context}}
Params: {{> "modules/mymodule/mymodule" title="Today is Thursday" state="cloudy"}}
To use precompiled Templates (bundled with the js-package) you need to do these things:
- create a handlerbars file with this pattern
_modulename_templatename.js.hbs
inside the module-folder. - write your template using handlebars syntax. example: https://github.com/unic/estatico/blob/develop/source/demo/modules/slideshow/_slideshow_slide.js.hbs
<div class="module_partial">Hello {{label}}</div>
### Using Precompiled template
add references to your module.
var templates = { partial: require('./_module_partial.js.hbs') };
require a handlebars template this way automatically makes it usable as handlebars-template inside your js-module.
parse template with data
var data = { label: 'estatico' }
var templateOutput = templates.foo(data); // output:
an example can be seen in the slideshow-demo-module: [slideshow.js#L6](https://github.com/unic/estatico/blob/develop/source/demo/modules/slideshow/slideshow.js#L6) and
[slideshow.js#L104](https://github.com/unic/estatico/blob/develop/source/demo/modules/slideshow/slideshow.js#L104)