How to "cut off" text to a specified number of characters?

Author Message

Maarten Holland

Tuesday 20 January 2004 11:31:24 am

Example:

I've got some articles in a folder. Each article starts with a 5-line intro. I've created an overviewpage that shows the name and full intro of every article in that folder. But I don't want to show the full intro: I only want to show the first two lines of it, followed by a 'read more'-link. Can anyone tell me how to do that?

Second question: How can I cut of long URL's in the middle, like it is done in this forum? I guess I have to modify a line-view?

Cheers,

Maarten

Hans Melis

Tuesday 20 January 2004 12:05:08 pm

Hi Maarten,

Q1: Use the shorten template operator. Example, {"This text is too long"|shorten(4)} produces "This..."

Q2: Either you use the shorten operator again if you have a hyperlink with a text description. Or you can use the autolink operator to detect URLs in a text and make them clickable that way. The autolink operator also takes one (optional) parameter: max characters.

--
Hans

Hans
http://blog.hansmelis.be

Tore Skobba

Wednesday 21 January 2004 2:20:04 am

Hmm using the shorten on an xml field might give broken xhtml. I.e

intro=A link is good

intro=A <a href="www.link.com">link</a> is good

intro.shorten(5)= "A <a ..."

I think at least

Cheers
Tore

Maarten Holland

Wednesday 21 January 2004 2:26:34 am

Thank you for your quick reply! I've got a small problem. Now I use the following code for showing the full description:
{$category.item.data_map.description.data_text}

When I change this into:
{$category.item.data_map.description.data_text|shorten(15, "... read more")}

nothing is showed. Source says:

<div class="date">
<?... read more
<BR /><BR />
</div>

The code:

{"This one works just fine!"|shorten(15, "... read more")} works fine. Do you know what's wrong with my first string?

Regards,

Maarten

Tore Skobba

Wednesday 21 January 2004 7:10:37 am

Does your data_text contain anything (debug output).. You do know that if it is an xml text field begning with some formating (15+ chars) then nothing will show.. Only some hidden html tags cause there referces are not there.

Hans Melis

Wednesday 21 January 2004 7:48:56 am

You're asking to shorten the pure XML, you should use the shorten operator on the HTML:

{$category.item.data_map.description.content|shorten(15)} for regular text fields. Or {$category.item.data_map.description.content.output.output_text|shorten(15)} for XML text fields.

--
Hans

Hans
http://blog.hansmelis.be

Maarten Holland

Wednesday 21 January 2004 12:21:33 pm

Thank you very much. I'd forgotten it's a XML-field. My bad. . . Works just fine now. Thank you both for your time!

Ulitsa Tal Arik

Friday 15 October 2004 4:15:14 am

How to "cut off" text, if I have table in description, this tag cut the piece of table and destroy the all design.... :(
It's very uncomfortable

plz help!!!

koban@inbox.ru

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.