Forums / Setup & design / How to "cut off" text to a specified number of characters?

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

eZ debug

Timing: Jan 19 2025 04:29:33
Script start
Timing: Jan 19 2025 04:29:33
Module start 'content'
Timing: Jan 19 2025 04:29:34
Module end 'content'
Timing: Jan 19 2025 04:29:34
Script end

Main resources:

Total runtime0.8623 sec
Peak memory usage4,096.0000 KB
Database Queries213

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0055 590.3281180.8125
Module start 'content' 0.00550.6837 771.1406671.7344
Module end 'content' 0.68920.1731 1,442.8750341.0547
Script end 0.8622  1,783.9297 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00370.4342210.0002
Check MTime0.00140.1598210.0001
Mysql Total
Database connection0.00070.076410.0007
Mysqli_queries0.782990.78952130.0037
Looping result0.00180.21062110.0000
Template Total0.837397.120.4187
Template load0.00200.230920.0010
Template processing0.835396.871520.4177
Template load and register function0.00020.021110.0002
states
state_id_array0.00080.087610.0008
state_identifier_array0.00080.096020.0004
Override
Cache load0.00170.1989530.0000
Sytem overhead
Fetch class attribute can translate value0.00140.166250.0003
Fetch class attribute name0.00130.1538100.0001
XML
Image XML parsing0.00290.335650.0006
class_abstraction
Instantiating content class attribute0.00000.0024110.0000
General
dbfile0.00480.5534320.0001
String conversion0.00000.000530.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 33
 Number of unique templates used: 6

Time used to render debug report: 0.0002 secs