Reputation: 4336
I want to truncate a string in Smarty
This is the scenario:
The string is "Test!abc".
Maximum characters allowed = 5.
Smarty gets string.
If I use {$string}
, I get the desired result "Test!abc"
If I use {$string|truncate:5:"..":true}
I get "Test&.."
How can I make truncate after html chars conversion. Prefer not to make it in php.
I know about "replace", but it will look like "|replace..|replace..|......"
Upvotes: 2
Views: 16632
Reputation: 7213
In Smarty 2 you can try this one
{$string|html_entity_decode|truncate:5}
Upvotes: 1
Reputation: 29508
You could try something like:
{$string|html_entity_decode:2:"UTF-8"|truncate:5:"...":true|htmlentities:2:"UTF-8"}
Upvotes: 3
Reputation: 13557
If you're using Smarty 3.1 you can have a look at the unescape modifier.
{$string|unescape:"entity"|truncate:5}
Upvotes: 3