Show your support for Zikula! Sign up at Github account and watch the Core project!
- nestormateo responded to »Zikula: Not Ready for Prime Time?« 08:57 AM
- krator responded to »Multiple Errors Migrating Dizkus 3,1 to Dizkus 3.2« 18. Jun
- mikebcoffee created topic »Convert modules to 'Gettext'« 18. Jun
- trichers created topic »Mobile Theme html5 and link with tel:« 18. Jun
- incasas responded to »Migrating Postcalendar 6.2 to Postcalendar 8.0« 17. Jun
- krator responded to »Error converting RATINGS and WEBLINKS« 16. Jun
Wiki » StringTruncating
There are several ways of doing this described below and some modifiers that might come in handy.
See also this Forum topic where a lot of string truncating is described∞.
- $string|truncate:80 will clip a string after a specified length and add ... to the truncated string. Use $string|truncate:100:'more':true to add the not the default ..., but more after the truncated string and truncate at the exact character instead of at a word boundary (the default). Truncating after a whole sentence is also possible. Beware however that HTML tags can get truncated as well. The rendering of your string can become messed up. Smarty truncate description∞.
In PHP you can do this with substr and wordwrap, but this is not as easy as the smarty modifier. Here are some examples of how to accomplish the same truncating in PHP.
- $string|truncatehtml:80 a new Zikula modifier that will clip a string on whole words after a specified length, but will keep the HTML tags intact. This means you can truncate a string with HTML markup in there and it will still render ok. It has an optional parameter for the suffix after truncating. The source can be found here in the ValueAddon News∞ project.
- $string|strip_tags this will remove all the HTML tags and replace them with a space. You can use this to clean out HTML tags and do a regular truncate after that. $string|strip_tags|truncate:80. See also Smarty strip_tags description∞.