I'd like to pass template data to a "textfield" helper method I have defined, like this:
{{textfield label="{{label}}"
id="account_{{attributes.id}}"
name="account[{{attributes.name}}]"
class="some-class"
required="true"}}
(note the {{label}} and {{attributes.id}} references inside the {{textfield}} helper call)
Here is where I set up the template:
data = {
"attributes": {
"id": "name",
"name": "name"
},
"label": "Name"
}
var templateHtml = 'markup here';
var template = Handlebars.compile(templateHtml);
var formHtml = template(data);
Here is a jsFiddle.
When I run this, I still see {{placeholders}} in the compiled markup.
How can I accomplish this?
You're using the incorrect syntax to pass named parameters to your handlebars helper. What you want is something like this:
var data = {
"attributes": {
"name": "name"
}
}
var templateHtml = '{{textfield name=attributes.name}}';
var template = Handlebars.compile(templateHtml);
var formHtml = template(data);
And an updated fiddle: http://jsfiddle.net/3yWn9/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With