Is it possible to pass a javascript literal object to a custom tag in jsrender?
for example something like this:
{{tag parameter={width: 200,
click: function(){
alert('clicked');
}
}
/}}
Right now it is not supported, assuming you don’t set
allowCode=true. JsRender templates are supposed to be side-effect free. A javascript literal{}is creating a new Object() so is not side-effect free. But you can pass in any object you want via template parameters/helpers. Many ways to to do that, e.g. declaring helpers on the template, declaring global helpers, passing in as an option in the.render(data, options)call… Then you just write{{tag parameter=~myPassedInObject}}. You can also have a helper that returns different objects, such as{{tag parameter=~myWidthObject(200,...)}},