MAZ
MAZ

Reputation: 214

CropViewHelper show HTML tags

I'm using format.crop ViewHelper in the template to crop the text.

The problem that the output display HTML tags :

ViewHelper :

<f:format.crop maxCharacters="250" respectHtml="false">{book.description}</f:format.crop>

Output HTML :

 <p>This is <p> and </p> HTML tags appears</p>

I tried both respectHtml="false" and respectHtml="true" but it's not works.

Upvotes: 0

Views: 717

Answers (1)

Daniel
Daniel

Reputation: 1085

Fluid by default escapes HTML to prevent Cross Site Scripting vulnerability.

This is by design. Integrators need to disable this behavior for specific areas. This can be done by using f:format.html or f:format.raw, while raw will prevent all security mechanisms and should therefore be used very rarely.

format.html does apply another configuration which defines which HTML tags and attributes are allowed: https://docs.typo3.org/m/typo3/reference-typoscript/master/en-us/Functions/Parsefunc.html

You concrete example could be:

<f:format.html>
    <f:format.crop maxCharacters="250" respectHtml="1">
        {book.description}
    </f:format.crop>
</f:format.html>

Or:

<f:format.raw>
    <f:format.crop maxCharacters="250" respectHtml="1">
        {book.description}
    </f:format.crop>
</f:format.raw>

If preferred, you could also use the inline notation:

{book.description -> f:format.crop(maxCharacters: 250, respectHtml: true) -> f:format.html()}

I would recommend to respect HTML, otherwise HTML might be broken, as closing tags might be cut off.

In case you do not want HTML output at all, use f:format.stripTags before applying f:format.crop, in order to remove HTML tags beforehand.

Upvotes: 2

Related Questions