简体   繁体   中英

Template as a variable in Handlebars.js

I'm creating an internationalized Ember.js app, for which I'm using Ember-I18n . This works fine in most scenarios, but now consider the language string:

'To do some action {{link}}'

Where {{link}} needs to be replaced with some link. The translation string cannot be broken up, since the position of {{link}} can differ from language to language. So instead I need to find a way to get the link in there; which is of course another template with a translation, something like:

<a {{action someAction}}>{{t click_here}}</a>

I've tried several things thusfar: creating a custom view for the link, using a custom block helper; but I havent' gotten anything to work yet.

What would be the best way to go about doing this? In other words, how can I get a rendered template as a variable to insert it into another template in Ember.js?

I do not use that library to translate my application, but as I understand from its documentation, this might work:

1) Create a view for the template like this:

var view = Em.View.create({
  templateName: "mytemplate",
  link: "http://emberjs.com",
});

2) Use in your template the bindings that Ember-I18n provide:

<a {{action someAction}}>{{t click_here linkBinding="view.link"}}</a>

Assuming that translation string is in the "click_here" key.

More info: https://github.com/jamesarosen/ember-i18n#bind-interpolated-values

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM