Durip
Durip

Reputation: 35

The F3::clean() function doesn't work as expected in template

I want use the F3::clean function in a template but it doesn't work. The function doesn't remove HTML tags. When I use function in controller, everything is working fine.

{{ F3::clean(@servisItem.description, 'br') | raw }}

I want to display servisItem.description with <br> and any other HTML code removed.

How can I do this?

Upvotes: 1

Views: 106

Answers (1)

xfra35
xfra35

Reputation: 3908

That's because variables passed to the template are HTML-escaped. Therefore there's no more any HTML tag to be stripped. See:

  • inside controller: <p>foo<br>bar</p>
  • inside template: &lt;p&gt;foo&lt;br&gt;bar&lt;/p&gt;

The best is to strip tags inside the controller, but if you absolutely need to do it inside the template, then you need to unstrip tags first:

{{ F3::clean(F3::decode(@servisItem.description), 'br') }}

Upvotes: 1

Related Questions