shorten operator with viewing attributes?

Author Message

Stefan van Zwoll

Thursday 23 September 2004 1:15:19 pm

hello,

i do display a specific class of objects on my frontpage (using a myclass_line.tpl file) and want to shorten the title and the intro to keep the design in place. as far as i understand the shorten operator, i tried all the versions to make that work - with no success. any suggestions?
it works fine with:

{$node.name|shorten(30)}

but not with:

<a href={$node.url_alias|ezurl}>{attribute_view_gui attribute=$node.object.data_map.teaser|shorten(120)}</a>

maybe i do have to change another template, but i don't know which that could be.
thank you very much in advance.
stefan

Paul Borgermans

Friday 24 September 2004 1:40:53 am

If the teaser attribute is simple text, try

EDITED: wrong

<a href={$node.url_alias|ezurl}>{attribute_view_gui attribute=$node.object.data_map.teaser.content|shorten(120)}</a>

EDITED: right

<a href={$node.url_alias|ezurl}>{$node.object.data_map.teaser.content|shorten(120)}</a>

If it is xml text, you will first have top strip the xhtml tags before shortening, otherwise your pages may become broken xhtml wise.

hth

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Stefan van Zwoll

Tuesday 28 September 2004 11:15:18 am

dear paul,

your version does not work either. instead of not showing a shortened version, your version produces no output at all with my templates.
the only version that works is by setting a length-limit in the admin-classes-tool. i thought there is another possibility though, since i want to show a shortened version on my frontpage, but the full teaser on the details page...

atb, stefan

Marko Žmak

Wednesday 29 September 2004 6:58:44 am

For a text line field (probably your title) try something like this:

<a href={$node.url_alias|ezurl}>{$node.object.data_map.title.content|shorten(120)}</a>

and for XML field (probably the intro):

<a href={$node.url_alias|ezurl}>{$node.object.data_map.intro.data_text|shorten(120)}</a>

but strip the XML tags first.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Siw Helen Thorslund

Thursday 30 September 2004 11:22:10 am

Same problem..

I want to shorten this:

{attribute_view_gui attribute=$node.object.data_map.intro}

Tried writing:

{attribute_view_gui attribute=$node.object.data_map.intro|shorten(10)}

Then like it was mentioned here:

{$node.object.data_map.intro.data_text|shorten(10)}

Nothing works...

Anyone with an idea?

www.VZT.no ( http://www.VZT.no )
VZT References ( http://http://vzt.no/index.php/vzt_eng/referanser )
VZT Extensions ( http://vzt.no/index.php/vzt_eng/extensions )
www.MediaBase.no ( http://www.MediaBase.no )

Marko Žmak

Thursday 30 September 2004 6:07:04 pm

What does "Nothing works..." exactly mean? Is the text displayed incorrectly or not displayed at all. Please specify.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Siw Helen Thorslund

Friday 01 October 2004 12:43:17 am

With "Nothing works..." I mean that none of the above solutions works.
None of them display anything.

As long as I add the |shorten(#) command, it shows nothing...

www.VZT.no ( http://www.VZT.no )
VZT References ( http://http://vzt.no/index.php/vzt_eng/referanser )
VZT Extensions ( http://vzt.no/index.php/vzt_eng/extensions )
www.MediaBase.no ( http://www.MediaBase.no )

Marko Žmak

Sunday 03 October 2004 3:23:54 pm

Try checking out if $node.object.data_map.intro.data_text relly exists and what type is it,like this:

{$node.object.data_map.intro|attribute(show)}

If you ommit the shorten operator and put just:

{$node.object.data_map.intro.data_text}

is the text displayed?

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Stefan van Zwoll

Tuesday 05 October 2004 8:29:44 am

on your first suggestion, ez crahes and reports a fatal error.
the second line of code produces no output at all.

i solved the problem by creating an "textline"-style attribute allowing no more than 120 letters length. its not the best version i believe, but a working one...

regards, stefan

Siw Helen Thorslund

Tuesday 05 October 2004 8:57:42 am

"i solved the problem by creating an "textline"-style attribute allowing no more than 120 letters length. its not the best version i believe, but a working one..."

How did you do this?

Could you put up a sample of that code?

Thanx,
Siw

www.VZT.no ( http://www.VZT.no )
VZT References ( http://http://vzt.no/index.php/vzt_eng/referanser )
VZT Extensions ( http://vzt.no/index.php/vzt_eng/extensions )
www.MediaBase.no ( http://www.MediaBase.no )

Stefan van Zwoll

Tuesday 05 October 2004 3:31:19 pm

actually, there is no code as such. i created a new class that has five attributes. one of them is the "teaser". i made it a textline since you can add a maximum length. in characters. all via the web-gui. i know that it is not the solution to the problem, but i had to figure out something since the project is due in two weeks...

greetings, stefan

Marko Žmak

Monday 11 October 2004 5:30:42 am

> on your first suggestion, ez crahes and reports a fatal error.
> the second line of code produces no output at all.

If the EZ crashes then could be something really wrong. Try this variant:

{$node.object.data_map.intro|attribute(show,1)}

One question? Does the class of the $node contain the intro attribute. If not then, you should substitute "intro" in the above code with the attribute that contains (e.g. "teaser"). And then try:

{$node.object.data_map.teaser.data_text}

if teaser is XML field, or:

{$node.object.data_map.teaser.content}

if tesaer is a text line. And of course, first fill tesaer with some test data like "Hello World" :)
Then report what happens.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Stefan van Zwoll

Monday 11 October 2004 8:36:31 am

since i cannot mess around with the content some editors have published already, i created a new attribute "test" to my class. i tried your code, this happened:

with the

...|attribute(show,1)

ez prints out a table with a header "attribute", "type" and "value". the fields are empty though. since it is a xml-textfield, i tried

{$node.object.data_map.teaser.data_text}

. this prints out the content i had previously entered for "test". since this works (it always did by the way), i tried the shorten-operator. again, this had only the effect that the content disappeared. can you conclude anything from this?

greetings, stefan

Paul Borgermans

Monday 11 October 2004 8:59:33 am

Did the content disappear in your web page completely (also when viewing the source)?

Also, could you post more of the template code, I suspect that you have syntax errors somewhere as you state that the shorten operator works on $node.name

Again, you can <b>not</b> use the shorten operator on xml/xhtml output without stripping the xml tags first. The latter can be done easily with adding the striptags operator as its direct php counterpart in template.ini:

PHPOperatorList[striptags]=strip_tags

If your teaser text field is xml text, the following should work:

{$node.object.data_map.teaser.content.output.output_text|striptags|shorten(60)}

{$node.object.data_map.teaser.content.output.output_text} will give you the xhtml output of the xml you entered there and this is better to feed to striptags than the raw xml

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Stefan van Zwoll

Monday 11 October 2004 9:29:55 am

yes, it works! finally. thank you very much, paul!
just in case somebody has the same prbs:
- add pauls line to the template.ini
- try the code offered, replacing "teaser" with your attribute title

thanks again, stefan

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 18 2025 19:05:26
Script start
Timing: Jan 18 2025 19:05:26
Module start 'layout'
Timing: Jan 18 2025 19:05:26
Module start 'content'
Timing: Jan 18 2025 19:05:27
Module end 'content'
Timing: Jan 18 2025 19:05:27
Script end

Main resources:

Total runtime0.8839 sec
Peak memory usage4,096.0000 KB
Database Queries97

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0077 588.0469152.6406
Module start 'layout' 0.00770.0028 740.687539.4766
Module start 'content' 0.01040.8720 780.1641793.0078
Module end 'content' 0.88250.0014 1,573.171932.1250
Script end 0.8838  1,605.2969 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.3672160.0002
Check MTime0.00140.1539160.0001
Mysql Total
Database connection0.00080.086110.0008
Mysqli_queries0.745884.3802970.0077
Looping result0.00140.1618950.0000
Template Total0.840095.020.4200
Template load0.00210.242320.0011
Template processing0.837894.787320.4189
Template load and register function0.00020.024410.0002
states
state_id_array0.00110.124110.0011
state_identifier_array0.00140.154120.0007
Override
Cache load0.00220.25171110.0000
Sytem overhead
Fetch class attribute can translate value0.00070.075040.0002
Fetch class attribute name0.00270.3098180.0002
XML
Image XML parsing0.00470.529540.0012
class_abstraction
Instantiating content class attribute0.00010.0070240.0000
General
dbfile0.00440.4962310.0001
String conversion0.00000.000940.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
15content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
32content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
9content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
14content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
9content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 81
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs