luukgruijs February 2016

Load handlebars js partial with different data

Is there a way to use a partial but include different data in it? Or in other words, can I include a template handlebars template in another template?

Basically something like this:

        <script id="countries-nav" type="text/x-handlebars-template">
            {{#each this}}
                <li class="item"><a href="#/countries/{{ISO}}">{{Country}}</a></li>
            {{/each}}
        </script>

    <script id="countryspecifics" type="text/x-handlebars-template">
        {{#each this}}
            <div class="country__title">
                <h2>{{title}}</h2>
            </div>
            {{> countries-nav}}
        {{/each}}
    </script>

Answers


Kuba Wyrobek February 2016

This is basic functionality of Blaze:

<template name="countries-nav">
    {{#each this}}
       <li class="item"><a href="#/countries/{{ISO}}">{{Country}}</a</li>
    {{/each}}
</template>

<template name="countryspecifics">
    {{#each this}}
        <div class="country__title">
            <h2>{{title}}</h2>
        </div>
        {{> countries-nav}}
    {{/each}}
</template>

Post Status

Asked in February 2016
Viewed 1,121 times
Voted 13
Answered 1 times

Search




Leave an answer