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.

eZ debug

Timing: Jan 19 2025 06:22:18
Script start
Timing: Jan 19 2025 06:22:18
Module start 'layout'
Timing: Jan 19 2025 06:22:18
Module start 'content'
Timing: Jan 19 2025 06:22:19
Module end 'content'
Timing: Jan 19 2025 06:22:19
Script end

Main resources:

Total runtime1.3917 sec
Peak memory usage4,096.0000 KB
Database Queries76

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0106 589.3984152.6563
Module start 'layout' 0.01060.0035 742.054739.5078
Module start 'content' 0.01411.3762 781.5625666.6250
Module end 'content' 1.39030.0014 1,448.187516.7188
Script end 1.3917  1,464.9063 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00770.5567160.0005
Check MTime0.00570.4090160.0004
Mysql Total
Database connection0.00080.056010.0008
Mysqli_queries1.302493.5808760.0171
Looping result0.00140.1038740.0000
Template Total1.340896.320.6704
Template load0.00210.149520.0010
Template processing1.338796.190120.6693
Template load and register function0.00010.010410.0001
states
state_id_array0.00240.171810.0024
state_identifier_array0.00250.177320.0012
Override
Cache load0.00190.1333530.0000
Sytem overhead
Fetch class attribute can translate value0.00100.074240.0003
Fetch class attribute name0.00130.0930100.0001
XML
Image XML parsing0.00890.642740.0022
class_abstraction
Instantiating content class attribute0.00000.0016110.0000
General
dbfile0.00840.6035210.0004
String conversion0.00000.000640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
8content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
13content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
7content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 33
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs