Passing data to Handlebars partials

If you have this:

const dummy_data = {
                toplinks : ['Shop','Publish','Read'],
                is_staff : true,
                latam : false,
                user : {
                    is_authenticated : true,
                    first_name : "John",
                    last_name : "Doe"
                },
                currentLanguage : 'DA',
                language : [
                    'DA',
                    'EN'
                ]
            };

        var template = Publish.templates.navigation,
            output = template( dummy_data );

            $('body').prepend( output );

Do this in the main template:

{{> toplinks toplinks=this.toplinks staff=this.is_staff}}

And this in the partial:

{{#each toplinks}}
    <a href="{{this}}" target="_blank" class="nav-btn">{{this}}</a>
{{/each}}

{{#if staff}}
    <a href="#" target="_top" class="nav-btn">Admin</a>
{{/if}}

Leave a Reply