dimanche 6 décembre 2015

Handlebars.js. Pass values to partials without hash-names

I use Handlebars as static template.

I wrote the partial for navbar item:

{{#*inline "item"}}
{{#equals tab current}}
    <li class="active">
        <a href="{{href}}">{{text}}</a>
    </li>
{{else}}
    <li>
        <a href="{{href}}">{{text}}</a>
    </li>
{{/equals}}
{{/inline}}

And I call them:

{{>item current=0 text="Link 1" href="#"}}
{{>item current=1 text="Link 2" href="#"}}
{{>item current=2 text="Link 3" href="#"}}

But I want to use shorter syntax, kind of this:

{{>item 0, "Link 1", "#"}}
{{>item 1, "Link 2", "#"}}
{{>item 2, "Link 3", "#"}}

Is there a way to use this syntax?




Aucun commentaire:

Enregistrer un commentaire