Search code examples
javascripthandlebars.jshandlebarshelper

Passing handlebars variable as parameter to partial


I have a partial that render a button like this:

{{>button classes="getting-started-button" icon="icon-rocket" text="Getting stared"}}

The problem is that the string i want to pass in text="Getting stared" is in itself a handlebars variable that looks like this

phrases.getting_started

If I add the to the partial call it should look something like this, but it doesn't work

{{>button classes="getting-started-button" icon="icon-rocket" text="{{phrases.getting_started}}"}}

So how do I solve this?

The partial looks like this:

<a 
    class="button {{classes}}" 
    href="{{#if href}}{{href}}{{else}}javascript:{{/if}}" {{#if btn-title}}title="{{btn-title}}"{{/if}}>
    <div class="button-inner">
        {{#if image}}
            <img src="{{image}}" alt="">
        {{else}}
            {{#if icon}}<i class="{{icon}}"></i><span>{{/if}}{{#if text}}{{text}}</span>{{/if}}
        {{/if}}
    </div>
</a>

Solution

  • It is even simpler than you thought:

    {{>button classes="getting-started-button" icon="icon-rocket" text=phrases.getting_started}}