$item...|shorten(100) is not working

Author Message

kavi kavi

Tuesday 23 January 2007 6:32:11 am

Hi everybody !
What's wrong with my code ?!
$item.object.data_map.intro.content.output.output_text is working without |shorten(100).
Is shorten is incompatible with $item ?!

{let nodes=fetch( 'content', 'list', hash( 'parent_node_id', 100,
'limit', 3,
'sort_by', array( 'published', false() )
))}

{foreach $nodes as $item}
<li class="article_atg">
<h1><a href="{$item.url}" title="titre">{$item.name}</a></h1>
<a href="{$item.url}" title="titre"><img src=""></img></a>
<p>
{def $mon_intro=$item.object.data_map.intro.content.output.output_text|shorten(100)}
<a href={$item.url} title="Lien vers : {$item.name}">{$mon_intro}</a>
</p>
</li>
{/foreach}
{/let}

kavi

Betsy Gamrat

Tuesday 23 January 2007 4:24:23 pm

kavi,

I would try


{def $mon_intro=$item.object.data_map.intro.content.output|shorten(100)}

and

{def $mon_intro=$item.object.data_map.intro.content|shorten(100)}

Xavier Dutoit

Tuesday 23 January 2007 11:56:19 pm

Hi,

You will have problem if your attribute is a xml block (or if it contains any html code), as it can cut it between the open and close tag.

I wrote an extension to take care of that problem, not 100% sure about the api, but will put it soon in the svn if you're interested.

X+

http://www.sydesy.com

kavi kavi

Wednesday 24 January 2007 1:20:33 am

Hi xavier!

I'm interested on your code. I'll see it...

I've find a solution but not the best i think...

Here is my code :
{let nodes=fetch( 'content', 'list', hash( 'parent_node_id', 100,
'limit', 3,
'sort_by', array( 'published', false() )))}
{foreach $nodes as $item}
<li class="article">
<h1><a href="{$item.url}" title="Lien vers : {$item.name}">{$item.name}</a></h1>
<p>
{def $mon_intro=$item.object.data_map.intro.content.output.output_text
$tab=$mon_intro|explode(' ')
$nb=$tab|count()
$tab1=$tab|extract(0,20 )}
<a href={$item.url} title="Lien vers : {$item.name}">{$tab1|implode(' ')}...</a>
</p>
</li>
{/foreach}

Thanks
kavi

Xavier Dutoit

Wednesday 24 January 2007 2:36:29 am

Hi,

Funny solution, wouldn't have tought about it. Bravo !

My extension let you keep some tags (eg, a b i) and truncate it.

Moreover, it secures ez publish, by cleaning properly all the XSS that you might got in if you have literal class=html activated (in my case, mandatory if I want to be able to have a ok looking RSS import).

X+

http://www.sydesy.com

kavi kavi

Thursday 25 January 2007 7:12:12 am

Salut xavier !

merci pour tes compliments qui me touchent beaucoup. cela fait 4 mois que j'ai découvert eZPublish et PHP...
Tu veux dire que ma solution est plus crédible que la tienne...?! ou c'est le contraire ? Je n'ai pas tout pigé...

kavi

Xavier Dutoit

Thursday 25 January 2007 8:02:21 am

Salut,

My solution is an extension that contains php code that does the work. It's more advanced than your solution (and likely to be faster too). I provides the ability to keep some tags (eg keep the bold and italic and links) and get rid of the others.

It also allows to protect your site against attack if you let your users to publish html code in your content (ie if you have the literal tag with "html" class).

X+

http://www.sydesy.com

Xavier Dutoit

Saturday 10 March 2007 2:52:43 am

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, even while using the html class for the literal tag.

X+

http://www.sydesy.com

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 31 2025 03:44:38
Script start
Timing: Jan 31 2025 03:44:38
Module start 'layout'
Timing: Jan 31 2025 03:44:38
Module start 'content'
Timing: Jan 31 2025 03:44:38
Module end 'content'
Timing: Jan 31 2025 03:44:38
Script end

Main resources:

Total runtime0.0232 sec
Peak memory usage6,144.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0056 588.1328151.2109
Module start 'layout' 0.00570.0037 739.3438220.6875
Module start 'content' 0.00940.0121 960.03131,005.9297
Module end 'content' 0.02140.0017 1,965.960941.9922
Script end 0.0231  2,007.9531 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.003113.1954140.0002
Check MTime0.00125.2248140.0001
Mysql Total
Database connection0.00072.926910.0007
Mysqli_queries0.002711.465830.0009
Looping result0.00000.043210.0000
Template Total0.00125.310.0012
Template load0.00094.059410.0009
Template processing0.00031.265310.0003
Override
Cache load0.00072.987710.0007
General
dbfile0.00135.451380.0002
String conversion0.00000.032940.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs