Replace all html special characters in Smarty

14,073

Solution 1

You could try something like:

{$string|html_entity_decode:2:"UTF-8"|truncate:5:"...":true|htmlentities:2:"UTF-8"} 

Solution 2

If you're using Smarty 3.1 you can have a look at the unescape modifier.

{$string|unescape:"entity"|truncate:5}

Solution 3

In Smarty 2 you can try this one

{$string|html_entity_decode|truncate:5}
Share:
14,073
lvil
Author by

lvil

r

Updated on June 25, 2022

Comments

  • lvil
    lvil almost 2 years

    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..|......"

  • lvil
    lvil over 12 years
    Thanks, but I am using Smarty 2
  • Michael Robinson
    Michael Robinson about 12 years
    @JohnMagnolia I couldn't agree more