Forums / Setup & design / shorten operator with viewing attributes?

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

eZ debug

Timing: Jan 18 2025 16:28:31
Script start
Timing: Jan 18 2025 16:28:31
Module start 'content'
Timing: Jan 18 2025 16:28:32
Module end 'content'
Timing: Jan 18 2025 16:28:32
Script end

Main resources:

Total runtime1.1962 sec
Peak memory usage4,096.0000 KB
Database Queries234

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0067 587.8438180.8125
Module start 'content' 0.00671.0358 768.6563798.1016
Module end 'content' 1.04260.1536 1,566.7578361.3047
Script end 1.1961  1,928.0625 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00450.3756210.0002
Check MTime0.00200.1663210.0001
Mysql Total
Database connection0.00100.079610.0010
Mysqli_queries1.074189.79642340.0046
Looping result0.00260.21462320.0000
Template Total1.162897.220.5814
Template load0.00220.186820.0011
Template processing1.160697.020520.5803
Template load and register function0.00010.011210.0001
states
state_id_array0.00100.084310.0010
state_identifier_array0.00090.078620.0005
Override
Cache load0.00210.17571110.0000
Sytem overhead
Fetch class attribute can translate value0.00270.226650.0005
Fetch class attribute name0.00070.0626180.0000
XML
Image XML parsing0.00180.152450.0004
class_abstraction
Instantiating content class attribute0.00010.0046240.0000
General
dbfile0.00460.3887420.0001
String conversion0.00000.000430.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
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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 81
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs