javascript - Pass variables to handlebars helper call -


i'd pass template data "textfield" helper method have defined, this:

{{textfield label="{{label}}"             id="account_{{attributes.id}}"             name="account[{{attributes.name}}]"             class="some-class"             required="true"}} 

(note {{label}} , {{attributes.id}} references inside {{textfield}} helper call)

here set template:

data = {   "attributes": {     "id": "name",     "name": "name"   },   "label": "name" } var templatehtml = 'markup here'; var template = handlebars.compile(templatehtml); var formhtml = template(data); 

here jsfiddle.

when run this, still see {{placeholders}} in compiled markup.

how can accomplish this?

you're using incorrect syntax pass named parameters handlebars helper. want this:

var data = {   "attributes": {     "name": "name"   } } var templatehtml = '{{textfield name=attributes.name}}'; var template = handlebars.compile(templatehtml); var formhtml = template(data); 

and updated fiddle: http://jsfiddle.net/3ywn9/1/


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -