最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is it possible to create variables in the doT.js templating engine? - Stack Overflow

programmeradmin1浏览0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 5

There 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.

发布评论

评论列表(0)

  1. 暂无评论