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: <div class='alert'>& Goodbye "world"</div>
Usage notes
- Common characters encoded:
<→<,>→>,&→&,'→',"→". - Plain text characters are not affected -- only reserved HTML characters are converted.
- Unlike most output helpers,
htmlEncodeis 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.