среда, 30 января 2019 г.

[Ckeditor] adds extra

html tags fix

If you pass HTML content to Twig template and escape it with raw filter/function, and get extra <p> tags, like in this example:

<p></p>
<p>my passed HTML content from CKeditor</p>
<p></p>

It means you should unwrap <p> tag, which wraps Twig content variable.
Bad Twig case:

<p>{{ page.content|raw }}</p>

Good Twig case:
{{ page.content|raw }}

It occurs because <p> cannot be nested, so tag cannot be unclosed, and if at next opens a new <p>, previous tag becomes automatically closed. 

Комментариев нет:

Отправить комментарий