I am using doT.js, a javascript templating engine. I would like to know if it is possible to use (helper-) variables like in the following example:
{{var foo = "bar"}}
<div>{{=foo}}</div>
Output:
<div>bar</div>
The above example does not work, but maybe there is another way. There doesn't seem to be any information about variables in the doT.js documentation.
I am using doT.js, a javascript templating engine. I would like to know if it is possible to use (helper-) variables like in the following example:
{{var foo = "bar"}}
<div>{{=foo}}</div>
Output:
<div>bar</div>
The above example does not work, but maybe there is another way. There doesn't seem to be any information about variables in the doT.js documentation.
Share Improve this question asked Jan 17, 2013 at 18:50 T. JunghansT. Junghans 11.7k8 gold badges54 silver badges77 bronze badges2 Answers
Reset to default 5There is a feature called 'pile-time defines' stated in 'default delimiters' of document. http://olado.github./doT/index.html
Examples can be found in https://github./olado/doT/blob/master/examples/advancedsnippet.txt
Here's the solution of your problem:
{{##def.foo="bar"#}}
<div>{{#def.foo}}</div>
{{var foo = "bar";}}
Should do the trick.