Forums / Developer / Shorten on object body attribute content text .. odd behaviour

Shorten on object body attribute content text .. odd behaviour

Author Message

Lo' F.

Sunday 07 November 2010 11:21:42 am

Hi there!

Here's another one!

There is a fetch statement which retrieves the content of a body attribute containing a picture.

Did that with another fetch of related objects, inside the main one, this way:

{def $items=fetch('content', 'tree', hash('parent_node_id', 2, .., 'class_filter_type', 'include', 'class_filter_array', array('article')))}
{foreach $itens as $item}
  {def $picts=fetch('content', 'related_objects', hash('object_id', $item.object_id))}
  {foreach $picts as pict}
    {if $pict.class_name|eq('Image')}
      {attribute_view_guy attribute=$pict.data_map.image image_class=small}
      {break}
    {/if}
  {/foreach}
  {$item.data_map.body.content.output.output_text|strip_tags()||shorten(300, '...')}
{/foreach}

Picture and body text are nicely displayed but...

The problem is: the text isn't made of the set number of chars but it varies in length, which is pretty strange.

It can't depend on the related picture, can it?

Anyone can help figure it out?

loredanaebook.it

Franck Magnan

Monday 08 November 2010 12:08:25 am

Hello Lo' F,

in your case, you put 2 "pipes" instead of one :

{$item.data_map.body.content.output.output_text|strip_tags()||shorten(300, '...')}

you may try to use only one "pipe" like this :

{$item.data_map.body.content.output.output_text|strip_tags()|shorten(300, '...')}

hope this helps

--
Developer at Open Wide

André R.

Monday 08 November 2010 1:59:42 am

Also note that there are extensions out there that does shorten a bit better on html output:

http://projects.ez.no/xmlwash

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Lo' F.

Friday 12 November 2010 12:14:20 pm

Hi Franck and Anrdre' and thanks for your reply.

"

...in your case, you put 2 "pipes" instead of one..

"

..just mistyped while reporting.. anyway...

Resolved the issue by activating wordCut extension (http://projects.ez.no/wordcut_extension) and replaced...

|shorten(300, '...')

with...

|word_cut(40)

loredanaebook.it

Steven E. Bailey

Saturday 13 November 2010 3:17:49 am

There is also http://projects.ez.no/smartshort

Certified eZPublish developer
http://ez.no/certification/verify/396111

Available for ezpublish troubleshooting, hosting and custom extension development: http://www.leidentech.com

Lo' F.

Saturday 13 November 2010 7:20:44 am

"

There is also http://projects.ez.no/smartshort

"

Good to know! Thank you Steven..

loredanaebook.it

eZ debug

Timing: Jan 18 2025 18:34:30
Script start
Timing: Jan 18 2025 18:34:30
Module start 'content'
Timing: Jan 18 2025 18:34:31
Module end 'content'
Timing: Jan 18 2025 18:34:31
Script end

Main resources:

Total runtime0.7727 sec
Peak memory usage4,096.0000 KB
Database Queries209

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0066 587.9688180.8047
Module start 'content' 0.00660.6407 768.7734684.5781
Module end 'content' 0.64740.1253 1,453.3516341.0234
Script end 0.7727  1,794.3750 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00390.4997210.0002
Check MTime0.00150.1907210.0001
Mysql Total
Database connection0.00080.104910.0008
Mysqli_queries0.661285.56862090.0032
Looping result0.00230.30002070.0000
Template Total0.746096.520.3730
Template load0.01291.669720.0065
Template processing0.733194.865820.3665
Template load and register function0.00010.016510.0001
states
state_id_array0.00150.188410.0015
state_identifier_array0.00090.120020.0005
Override
Cache load0.01241.6058450.0003
Sytem overhead
Fetch class attribute can translate value0.00130.168950.0003
Fetch class attribute name0.00230.2944100.0002
XML
Image XML parsing0.00350.453650.0007
class_abstraction
Instantiating content class attribute0.00000.0029120.0000
General
dbfile0.00490.6350460.0001
String conversion0.00000.001030.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
6content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
6content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
14content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
5content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
2content/datatype/view/ezxmltags/quote.tpldatatype/ezxmltext/quote.tplextension/ezwebin/design/ezwebin/override/templates/datatype/ezxmltext/quote.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 37
 Number of unique templates used: 8

Time used to render debug report: 0.0002 secs