Skip to content
Florian Süsstrunk edited this page Dec 15, 2016 · 24 revisions

Handlebars

...

Handling Data

...

Dynamic Partials

In order to include partial based on data the handlebars helper dynamicPartial can be used. please follow the examples on this page: Handlebars Page

Passing data to partials

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"}}

Precompiled Templates (JS)

To use precompiled Templates (bundled with the js-package) you need to do these things:

creating a js-template

<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:

Hello estatico

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)

estatico is made by unic & the community. feel free to give feedback and extend these documents

Clone this wiki locally