John
John

Reputation: 6612

Use a variable as template variable

I have a page header template, which has a title variable like so:

{{> pageHeader title="questions"}}

<template name="pageHeader">
  <h1>{{title}}</h1>
</template>

This works fine. But I use i18n to set my titles, like {{i18n 'title'}}. How can I use this in the template call? When I use this it doesn't work:

{{> pageHeader title="{{i18n 'title'}}"}}

Upvotes: 1

Views: 72

Answers (2)

Marcelo Schmidt
Marcelo Schmidt

Reputation: 619

You can resolve the i18n in your .js file.

Your template would be

{{> pageHeader title=i18nTitle}}

and you'd have a helper that would solve for the i18n

Template.xxx.helpers({ i18nTitle: function() { return i18nMethod('title'); } });

Upvotes: 1

PhilippSpo
PhilippSpo

Reputation: 789

Not yet on master branch of meteor but on develop: https://github.com/meteor/meteor/issues/5066
If you update to the 1.2 release candidate you can already use this feature. Update to the rc:

meteor update --release [email protected]

Use the nested sub-expressions:

{{> pageHeader title=(i18n 'title')}}

Upvotes: 4

Related Questions