最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Passing handlebars variable as parameter to partial - Stack Overflow

programmeradmin4浏览0评论

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>

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>
Share Improve this question asked Nov 20, 2017 at 9:14 arpoarpo 1,9092 gold badges28 silver badges51 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

It is even simpler than you thought:

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

评论列表(0)

  1. 暂无评论