Show your support for Zikula! Sign up at Github account and watch the Core project!
- craigh responded to »Numerous 404 errors on Zilkula site - what's up?« 18. Apr
- bronto responded to »High Bandwith Usage« 15. Apr
- drak responded to »zikula.com.au« 03. Apr
- Paustian responded to »Migrating from PostNuke to Zikula« 01. Apr
- mesteele101 responded to »Zikula 1.2.10 - set default replyto address for new user email« 31. Mar
- portugao responded to »Redirect to specific page on login« 30. Mar
- localrags responded to »Broken RSS when running Mobile theme« 30. Mar
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∞.