Articles in this section

htmlEncode helper

The htmlEncode helper converts reserved HTML characters such as <, >, &, ', and " into their HTML entity equivalents. Use it when embedding field values in HTML templates or transmitting text that should not be interpreted as markup.

Syntax

{{htmlEncode value}}

value -- The string to encode. Required.

Examples

Encode HTML-sensitive characters in a field

{{htmlEncode record.content}}

Input:

{ "record": { "content": "<div class='alert'>& Goodbye \"world\"</div>" } }

Output: &lt;div class=&#39;alert&#39;&gt;&amp; Goodbye &quot;world&quot;&lt;/div&gt;

Usage notes

  • Common characters encoded: < → &lt;, > → &gt;, & → &amp;, ' → &#39;, " → &quot;.
  • Plain text characters are not affected -- only reserved HTML characters are converted.
  • Unlike most output helpers, htmlEncode is safe to use with double braces ({{ }}). Triple braces are not required and would cause the encoded entities to be output as raw text.
  • To decode HTML entities back to their readable form, use the htmlDecode helper instead.