Reputation: 97
How can i add expressions to partials parameters? I want to do something like that:
{{> myPartial greeting=(i18n.greeting + "my text") }}
Upvotes: 2
Views: 964
Reputation: 79
That depends in how your configure the server options with nodeJS I configured the functions in res.locals (Version Express Over 4.0) with a '__' expression so in the example look like this
{{> myPartial greeting=(i18n 'greeting')}}
Your JSON file in locales should have this key and it'd be magic...
By the way to concat your key with any string should be this way
{{> myPartial greeting=(i18n 'Hello %s', 'Marcus')}}
I hope you find this useful..
Upvotes: 0
Reputation: 8993
The Handlebars documentation has a section on subexpressions. It tells us that the way to pass the results of inner helper as the argument to outer helpers is done as follows:
{{> myPartial greeting=(i18n 'greeting') }}
However, it looks from your question that you might be trying to concatenate some string values into a single greeting
parameter for your partial. If this is the case, you will need to create (or import) a helper that will concatenate strings for you and then apply this helper as another subexpression. The result would look like the following:
{{> myPartial greeting=(concat (i18n greeting) 'my text') }}
The required helper could be done as follows:
Handlebars.registerHelper('concat', function () {
return Array.prototype.slice.call(arguments, 0, -1).join('');
});
Upvotes: 2