rife.render.EncodeJson - rife2/rife2-template-renderers GitHub Wiki

Encodes a template value to JSON.

Usage

<!--v render:rife.render.EncodeJson:valueId/-->
{{v render:rife.render.EncodeJson:valueId/}}

Sample

Template

{
    "sample": "{{v render:rife.render.EncodeJson:sample/}}"
}

Code

template.setAttribute("sample", "This is a \"•test\"");

Output

{
    "sample": "This is a \"\u2022test\""
}

Properties

By default, the rendered data is raw, not template encoded. If you need additional encoding, use the encoding property.

For example, to encode the rendered data to HTML:

{{v render:rife.render.EncodeJson:valueId}}
encoding=html
{{/v}}

The supported additional encoding types are:

  • html
  • js
  • json
  • unicode
  • url
  • xml