Escape double braces {{ … }} in Mustache template. (templating a template in NodeJS)

后端 未结 6 2244
萌比男神i
萌比男神i 2020-12-05 02:28

I\'m trying to template a template, like below:

{{{
{
  \"name\" : \"{{name}}\",
  \"description\" : \"{{description}}\"
}
}}}

{{{debug this}}}
6条回答
  •  半阙折子戏
    2020-12-05 03:04

    You can switch delimiters to something that won't conflict with the triple mustaches, like erb-style tags:

    {{=<% %>=}}
    {{{
    {
      "name": "<% name %>",
      "description": "<% description %>"
    }
    }}}
    {{{debug this}}}
    <%={{ }}=%>
    

    Note that you can do this as many times as you like throughout your template. Any time you run into something that conflicts, pick a new set of delimiters :)

提交回复
热议问题