Skip to content

rife.render.EncodeJson

Erik C. Thauvin edited this page Mar 28, 2023 · 3 revisions

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