luukgruijs
luukgruijs

Reputation: 129

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>

Upvotes: 1

Views: 64

Answers (1)

Kuba Wyrobek
Kuba Wyrobek

Reputation: 5273

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>

Upvotes: 0

Related Questions