Shorten your text with truncate

Have you ever had the need to display only a short bit of text, for example from News module?
Here comes smarty to help with truncate tag like this.


As an example you can look at my footer links where i used truncate to shorten the links created by RSS2HTML module.


The same can be used with News module where you would do something like this.

{if $entry->summary}
    {eval var=$entry->summary|truncate:100:"...":true|strip_tags}
{else if $entry->content}
    {eval var=$entry->content|truncate:100:"...":true|strip_tags}

Now our News article will be truncated to 100 characters and with strip_tags modifier html tags will be removed so we can prevent wrong markup.

If you want to know more about it, you can take a look at official Smarty site

Technorati claim: 8U5J3DQ8KSKY