Forums / Setup & design / If-then-else and is_empty
Trond Hjelmaas
Thursday 28 April 2005 12:16:33 am
Hi,
I have two sorts of articles in one "News" folder. I take the 4 most recent and put their title (or name) at the frontpage(and a "Read more" link) .
The problem is that article type 1 has a title and article type 2 has no title but a name (yes, it does make sense :) ).
So my problem is that when I use "is_empty" on a title it works fine, however, when there is no title (only a name) I don't get the {section-else} printed.Look at this code:
{section show=$:item.object.data_map.title.content.is_empty|not} {attribute_view_gui attribute=$:item.object.data_map.title}; {section-else} {attribute_view_gui attribute=$:item.object.data_map.name}; {/section}
The "is_empty" part is my problem. I cannot test if the title is empty (or full) when an article has a name only...
Can I switch the "is_empty" with "does_exists" or something like that? Any other suggestions are very welcome :)
Thanks in advance!
Trond H
Eivind Marienborg
Thursday 28 April 2005 12:19:19 am
Maybe is_valid could work?
Thursday 28 April 2005 12:29:12 am
Thanks for suggestion, I tried:{section show=$:item.object.data_map.title.is_valid}
and {section show=$:item.object.data_map.title.content.is_valid}
but it goes to {section-else} 100% of the time.
Any other suggestions :) ?
Thursday 28 April 2005 12:38:58 am
How about setting up the title as name pattern for the article that has a title? Then you could print
$:item.name
on both classes.
Thursday 28 April 2005 12:41:54 am
That sounds like a great idea!, but I don't know how to create a "name pattern". Would you have any more information?
Thanks again :)
Thursday 28 April 2005 12:47:46 am
Edit your class, you'll probably see it right away, right at the top, along with class name and identifier :)
Thursday 28 April 2005 1:55:00 am
Hi, found the name pattern. I also search for help using this attribute, not much luck with examples.
I currently have article class (default) withObject name pattern: <short_title|title>
Do you have any suggestion how I add "name" in here? My intuition says something like <short_title|title|name=title>...
Would you have a link to documentation regarding "object name pattern" and/or "is_empty/is_valid" attributes?
Thanks
Thanks and thanks
Thursday 28 April 2005 2:03:53 am
The $:item.name is set by the object name pattern. So if you set your name pattern to <title>, accessing $:item.name will output the same as $:item.object.data_map.title.
Regarding is_valid/is_empty, I'd recommend a search through the docs/forum here on ez.no, and a grep through the standard templates for examples.
Tore Skobba
Thursday 28 April 2005 4:00:14 am
Hi
Try to use the "has_content" instead (http://www.ez.no/ez_publish/download/changelogs/ez_publish_3_4/datatype_changes )
Norman Leutner
Wednesday 08 June 2005 7:14:31 am
That doesn't seem to be the best way.. If you edit the object any remove attribute,.has_content still keeps true.
--> has_content boolean true
Mit freundlichen Grüßen Best regards Norman Leutner ____________________________________________________________ eZ Publish Platinum Partner - http://www.all2e.com http://ez.no/partners/worldwide_partners/all2e_gmbh
Marko Žmak
Wednesday 08 June 2005 10:35:01 am
You could also try:
is_set($:item.object.data_map.title)
-- Nothing is impossible. Not if you can imagine it! Hubert Farnsworth