raw
Usage
Variables and methods outputted in Twig templates in Winter are automatically escaped by default for security reasons. If you wish to display the raw data without any escaping, use the | raw
filter.
{% set html = "<strong>Hi</strong>" %}
{{ html }}
{# Outputs as "<strong%gt;Hi</strong%gt;" #}
{{ html | raw }}
{# Outputs as "<strong>Hi</strong>" #}
NOTE: Exercise extreme caution when using this filter with user-inputted data.
Be careful when using the raw
filter inside expressions:
{% set hello = '<strong>Hello</strong>' %}
{% set hola = '<strong>Hola</strong>' %}
{{ false ? '<strong>Hola</strong>' : hello | raw }}
{# The above will not render the same as #}
{{ false ? hola : hello | raw }}
{# But renders the same as #}
{{ (false ? hola : hello) | raw }}
Copyright © 2024 Winter CMS