问题
I have a participant being rendered in this template:
<template name="participant">
<div class="animated fadeIn">
<a href="{{pathFor 'participants'}}">← Back</a>
{{#with participant}}
<div class="participant">
<h3>{{fullname}}</h3>
<dl>
<dt>E-mail</dt>
<dd>{{email}}</dd>
<dt>Phone</dt>
<dd>{{tel}}</dd>
<dt>City</dt>
<dd>{{zip}} {{city}}</dd>
<dt>Creation time</dt>
<dd>added {{created_on}}</dd>
</dl>
{{>quickfield name="email" value=email}}
<p> </p>
<h5><a href="#" class="delete">Delete</a></h5>
</div>
{{/with}}
</div>
</template>
Where Quickfield template is:
<template name="quickfield">
<input id="{{name}}" value="{{value}}" class="bound">
</template>
I would like to skip the second parameter, called "value", in the template call, as it is the same as the name parameters. We should be able to build the template with only one parameter.
Ideally, I should have this:
{{>quickfield name="email"}}
<template name="quickfield">
<input id="{{name}}" value="{{eval('this.' + name)}}" class="bound">
</template>
But that doesn't work. How can I do?
Thks!
回答1:
Create an additional helper:
UI.registerHelper('get', function(name) {
return this[name];
});
Now you can rewrite your template as:
<template name="quickfield">
<input id="{{name}}" value="{{get name}}" class="bound">
</template>
来源:https://stackoverflow.com/questions/24199949/meteor-handlebars-template-how-to-eval-parameters