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.