Hi meteorites,
I’ve searched for a solution on the www, did not succeed sadly. Before declaring my problem here is some code I have trouble with:
<i class="mdi-action-account-circle prefix"></i>
<label for="firstName" class="{{active}}">{{i18n 'persons.firstName'}}</label>
<input id="firstName" type="text" value="{{get 'firstName'}}">
</div>
Having a html file full of that code for multiple inputs is tedious, so I thought it might be clever to use templates for it:
{{> textInput propertyName='firstName' iconName='mdi-action-something' langString='persons.firstName'}}
All my inputs are wrapped inside
{{#with personDetails}}
so I can have a database instance of a person inside all my template helpers 'n stuff.
Now, most of you might know, that using variables in template inclusions overrides this
(took me a while to figure that out). Id like to find a way to merge all parameters into this
(which has to be the instance of a person object from the collection), or better have it in a variable like parameters
inside helpers. So I can create something like this
<template name="genericInput">
<div class="input-field col {{inputSize}}">
<i class="{{iconName}} prefix"></i>
<label for="{{propertyName}}" class="{{active}}">{{i18n langString}}</label>
<input id="{{propertyName}}" type="text" value="{{get propertyName}}">
</div>
</template>
Get looks like this:
Template.registerHelper("get", function(property) {
if (this[property]) {
return this.get(property);
}
});
this
in the helper is also the instance of a person from the collection.
The i18n function1 in this code is working, and they seem to have found a solution which looks something like this:
/*
Register handlebars helper
*/
if(Meteor.isClient) {
if(UI) {
UI.registerHelper('i18n', function () {
return i18n.apply(this, arguments);
});
} else if(Handlebars) {
Handlebars.registerHelper('i18n', function () {
return i18n.apply(this, arguments);
});
}
}
but I don’t really understand what’s happening there.