return $r; } /** * @param int $page 页数 * @param int $pagesize 每页显示数量 * @return mixed */ function link_find($page = 1, $pagesize = 100) { $arr = link__find($cond = array(), array('rank' => -1), $page, $pagesize); return $arr; } /** * @param $id * @return bool 返回FALSE失败 TRUE成功 */ function link_delete($id) { if (empty($id)) return FALSE; $r = link__delete(array('id' => $id)); link_delete_cache(); return $r; } //--------------------------kv + cache-------------------------- /** * @return mixed 返回全部友情链接 */ function link_get($page = 1, $pagesize = 100) { $g_link = website_get('friends_link'); if (empty($g_link)) { $g_link = link_find($page, $pagesize); $g_link AND website_set('friends_link', $g_link); } return $g_link; } // delete kv and cache function link_delete_cache() { website_set('friends_link', ''); return TRUE; } ?>javascript - Gruntjs changing underscore template delimiters - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Gruntjs changing underscore template delimiters - Stack Overflow

programmeradmin1浏览0评论

I'm trying to generate a JSP page, and since the template delimiters used by JSP's are the same as the ones used by underscore.

looking at the docs --> .template#wiki-grunt-template-setDelimiters i can see they have a function for that

grunt.template.addDelimiters(name, opener, closer)

Two questions:

  1. Where would i call that function ?
  2. Can i change the delimiters only for a grunt.template.process() ( i have more than one, and for other non .jsp templates, the default delimiters are fine ) ?

Any help is appreciated. Thanks.

I'm trying to generate a JSP page, and since the template delimiters used by JSP's are the same as the ones used by underscore.

looking at the docs --> https://github./gruntjs/grunt/wiki/grunt.template#wiki-grunt-template-setDelimiters i can see they have a function for that

grunt.template.addDelimiters(name, opener, closer)

Two questions:

  1. Where would i call that function ?
  2. Can i change the delimiters only for a grunt.template.process() ( i have more than one, and for other non .jsp templates, the default delimiters are fine ) ?

Any help is appreciated. Thanks.

Share Improve this question edited May 22, 2013 at 8:39 mfreitas asked May 22, 2013 at 8:10 mfreitasmfreitas 2,4053 gold badges32 silver badges42 bronze badges 1
  • have you tried... escaping the characters, for when it processes the text, it gets printed the way you want? – Gonçalo Vieira Commented May 22, 2013 at 8:50
Add a ment  | 

2 Answers 2

Reset to default 8

from the documentation for grunt.template.process:

The default template delimiters are <% %> but if options.delimiters is set to a custom delimiter name, those template delimiters will be used instead.

that basically would mean that you can call grunt.template.process with the name of the delimiter you added before.

e.g. if you want to use square-brackets as delimiters in one processing step that should do the job:

// first add the new delimiters which you want to use
grunt.template.addDelimiters('square-brackets', '[', ']');

//  and use it
grunt.template.process(template, {delimiters: 'square-brackets'});

// and use it with the default delimiters (named 'config')
grunt.template.process(template);

I have exactly the same issue. JSP uses <%= %> tags for its replacement which are also used by grunt. Added a line to overwrite the default setting applied in "https://github./gruntjs/grunt/blob/master/lib/grunt/template.js"

This worked for me:

// REPLACE the default 'config' delimiters
grunt.template.addDelimiters('config', '{%', '%}');

grunt.initConfig(
    { .... });

The delimiter name 'config' must match exactly.

发布评论

评论列表(0)

  1. 暂无评论