Show your support for Zikula! Sign up at Github account and watch the Core project!
- Paustian responded to »What's going on with 1. the documentation | 2. the AppStore« 01:07 PM
- Paustian responded to »Shared user database« 12:49 PM
- Paustian responded to »Problems: module "htmlpages« 12:48 PM
- bronto responded to »Forcing a theme for particular URLs« 22. May
- Paustian created topic »Dealing with a Huge User List« 21. May
- Paustian responded to »Manual Zikula 1.2.9 (dev) to Zikula 1.3.5 update« 21. May
- krator responded to »Refresh Templates/Cache« 19. May
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∞.