shorten
Summary
Returns a shortened version of the input string.Usage
input|shorten( [ length [, sequence [, trim_type ] ] ] )
Parameters
Name | Type | Description | Required |
---|---|---|---|
length | integer | The desired length of the returned string. | No. |
sequence | string | Custom trailing/end-sequence. | No. |
trim_type | string | Controls the type of trimming: "right" (default) or "middle". | No. |
Returns
A shortened version of the input string.Description
This operator shortens the input string to "length" characters and adds a trailing sequence. Please note that the "length" parameter also includes the length of the trailing sequence. If the input string is shorter than "length", it will not be shortened. The default length is 80, the default trailing sequence is three dots: "...". The third parameter controls the type of trimming, it can be set to either "right" (default) or "middle".
Examples
Example 1
{'Led Zeppelin rocks!'|shorten( 15 )}
The following output will be produced: "Led Zeppelin...".
Example 2
{"eZ Systems"|shorten( 7, '...' , 'middle' )}
The following output will be produced: "eZ...ms".
Balazs Halasy (05/02/2004 10:59 am)
Svitlana Shatokhina (06/04/2006 1:46 pm)
Comments
Beware of xml :)
Thursday 01 March 2007 2:46:10 pm
P. Renaud
A solution is to use the Php strip_tags operator, as follows :
In order to be able to use strip_tags, you have to add it to authorized eZ template operators. Edit the template.ini.append.php file of your siteaccess (create it if it does not exist), and add
Forum links :
http://ez.no/community/forum/setu...g_text_from_summarizing_ezxmltext__1
http://ez.no/community/forum/deve...e_item_shorten_100_is_not_working__1
A more flexible way
Saturday 10 March 2007 10:46:24 am
Xavier
This extension allows to shorten the xml result, even while keeping all (or a selection of) xml tags.
http://projects.ez.no/xmlwash
as an added bonus, it offers a bigger security, no matter your ez config.
Beware of entities
Friday 30 November 2007 3:45:30 pm
Adrien
$str|shorten(count($alt),$alt) permet donc de remplacer la chaîne $str par $alt dès que $str est plus longue que $alt.
Let test the ellipsis :
|shorten(80)
Lorem ipsu10m dolor 20sit amet30, consec40tetur ad50ipisicin60g elit, 70sed...
|shorten(80,'')
Lorem ipsu10m dolor 20sit amet30, consec40tetur ad50ipisicin60g elit, 70sed do
|shorten(80,'…')
Lorem ipsu10m dolor 20sit amet30, consec40tetur ad50ipisicin60g elit, 70sed d…
|shorten(80,'…')
Lorem ipsu10m dolor 20sit amet30, consec40tetur ad50ipisicin60g elit,…
|shorten(87,'…')
Lorem ipsu10m dolor 20sit amet30, consec40tetur ad50ipisicin60g elit, 70sed d…
If you don't want the ellipsis, just say it.
If you wan't the UTF-8 real ellipsis, use the HTML entity and add 7 to the desired length to correct the entity count.
Re: Beware of entities
Friday 30 November 2007 3:53:08 pm
Adrien