If-then-else and is_empty

Author Message

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?

Trond Hjelmaas

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 :) ?

Eivind Marienborg

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.

Trond Hjelmaas

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 :)

Eivind Marienborg

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 :)

Trond Hjelmaas

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) with
Object 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

Eivind Marienborg

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

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 06:27:57
Script start
Timing: Jan 31 2025 06:27:57
Module start 'layout'
Timing: Jan 31 2025 06:27:57
Module start 'content'
Timing: Jan 31 2025 06:27:57
Module end 'content'
Timing: Jan 31 2025 06:27:57
Script end

Main resources:

Total runtime0.0147 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0067 588.1328151.2109
Module start 'layout' 0.00670.0020 739.343836.6484
Module start 'content' 0.00880.0047 775.9922102.2656
Module end 'content' 0.01350.0011 878.257841.9922
Script end 0.0146  920.2500 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002718.3233140.0002
Check MTime0.00117.5164140.0001
Mysql Total
Database connection0.00064.333110.0006
Mysqli_queries0.002818.956730.0009
Looping result0.00000.082810.0000
Template Total0.00096.010.0009
Template load0.00074.442010.0007
Template processing0.00021.539710.0002
Override
Cache load0.00043.045210.0004
General
dbfile0.00138.918080.0002
String conversion0.00000.053640.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