Search code examples
escapingjsrender

How can I render the string `{{string}}` within a jsrender template?


Is it possible to render a string wrapped in double curly braces in JSRender?

<div>
   <p>Can I render {{string}} instead of something looking like a {{customtag}}?</p>
   {{if myCustomTag && myTag}}
      (<em>{{:myTag}}</em>)
   {{/if}}
</div>

So far my attempts at http://www.jsviews.com/ have come back void.


Solution

  • You can use HTML character entities - &#123; for { and &#125; for } (or equivalently &lcub; and &rcub;)

    So in a template,

    ... &#123;&#123;string&#125;&#125; ...

    will render as

    ... {{string}} ...

    In fact the parser is looking for {{ and {^{ as tag delimiters, so you can get away with using:

    ... {&#123;string&#125;} ...


    This is covered by the following new documentation topic: https://www.jsviews.com/#escapetag