I have a string with 69 characters:
This is a test with characters like € or "like this". How 'bout that?
I use CKEditor in my form and make the word 'test' bold. This is how it is saved it the database:
<p>This is a <strong>test </strong>with characters like € or "like this". How 'bout that?</p>
If I want to show the string without any markup I use the Twig-filters striptags
and raw
after each other which results in:
This is a test with characters like € or "like this". How 'bout that?
Now of the original string I want to show the first 65 characters without any styling. I use the Twig-filter truncate (65)
.
This is my code in Twig:
{{ string | striptags | raw | truncate (65) }}
My result is
This is a test with characters like € or "like this&quo...
As you can see the special characters are shown as their HTML entity name, even though I only added the truncate
filter. Is this a bug or should this be expected? The same thing happens when I use the slice
filter.
My result should be:
This is a test with characters like € or "like this". How 'bout
EDIT: I understand what the issue is now. When using the raw
filter on a string this does not mean any of the original characters from that string (i.e. the HTML entity names) will not be counted when using slice
or truncate
filter. I still have not found a solution though.