What is the alternative to the |raw
filter if I want to output html from a entity field in twig in Drupal 8?
According to this ticket, |raw
should be avoided, but I can't figure out how to use what they recommend in that ticket (Safestring/SafeMarkup) in twig.
I have a custom content entity that has a field definition as follows:
$fields['internal_description'] = BaseFieldDefinition::create('text_long')
->setLabel(t('Internal description'))
->setSettings(array(
'max_length' => 1500,
))
The field stores HTML from a CKEditor instance. Now I would like to output this as HTML in a twig template. Currently if I just call
{{ event.getExternalDescription }}
I get the escaped HTML as expected, however that is not what I want. If I do
{{ event.getExternalDescription | raw }}
I get what I want, which is unescaped, rendered HTML. However since it's not checked in any way in this case, I would like to know how to make this output safe and still allow my users to use CKEditor for entering content?