Forums / Setup & design / How do I not show empty fields in custom class' output?

How do I not show empty fields in custom class' output?

Author Message

Valentin Svelland

Friday 18 July 2003 3:11:05 am

I've made a new content class called "services" for describing - well - services my company delivers. The attributes of this class are title, description, contact_info and so on. However, sometimes there is no contact_info and I need a check to exclude this attribute's header from the output-file services.tpl.

A suggestion about how to write a switch to check if this attribute is empty, and if so exclude the following code, would be much appreciated:

(from services.tpl)

<switch ??>
<h3>Contact information</h3>
{attribute_view_gui attribute=$content_version.data_map.contact_info}
<br /><br />

enigmista enigmista

Friday 18 July 2003 4:13:25 am

same problem

Valentin Svelland

Friday 18 July 2003 4:19:17 am

If found a solution. This works but I'm not sure it's the best way to do this:

{switch match=$node.object.data_map.contact_info.data_int}
{case match=1}
<h2 class="services">Contact information:</h2>
{attribute_view_gui attribute=$content_version.data_map.contact_info}
<br /><br />
{/case}
{case}
{/case}
{/switch}

Karsten Jennissen

Friday 18 July 2003 4:20:45 am

I think it's best to use {section show=... for this

See here for more info:
http://ez.no/developer/ez_publish_3/documentation/development/libraries/ez_template/functions/section

Karsten

Valentin Svelland

Friday 18 July 2003 4:46:31 am

Hey Karsten. Trying to figure out the section show-bit. Any more clues, read your link but still not there..

Bjørn Kaarstein

Friday 18 July 2003 4:48:17 am

This works if your field is a text line.

{switch name=empty match=$:item.data_map.contact_info.data_text}

{case match=''}
The textfield is empty
{/case}
{/switch}

To find out which attributes you can check, (and their values), try: {$:item.data_map|attribute(show)} within your section loop.

This might get you a bit closer...

Regards Bjørn

Karsten Jennissen

Friday 18 July 2003 4:58:36 am

Can't test, but it should go like this:

{section name=contactinfo show=$content_version.data_map.contact_info}
<h3>Contact information</h3>
{attribute_view_gui attribute=$content_version.data_map.contact_info}
{/section}

Bjørn Kaarstein

Friday 18 July 2003 5:23:56 am

Valentin: Please post a message when you figure it out.
Could be very useful in the future :)

thx

Regards Bjørn

Valentin Svelland

Friday 18 July 2003 5:51:36 am

The section show-way isn't working out as this code doesn't regard data_text='' to be empty or whatever. The switch-way let's me test for this, but I wan't to trigger my statement when the data_text has text in it.. I'm not quite sure how to express an else in the switch statement in other words...
-------------------------------
Attribute Type Value
data_text string ''
-------------------------------

{switch match=$:item.data_map.contact_info.data_text}
{case match=''}{/case}

{case else}
<h2>Contact info:</h2>
{attribute_view_gui attribute=$content_version.data_map.contact_info}
{/case}

{/switch}

..how do I write this in valid code??

Karsten Jennissen

Friday 18 July 2003 6:10:00 am

Really, if you want to show a certain section in a template, the best thing to do is section show. If you want to check for data_text, then use this in your show= statement. If the switch statement works then the show= statement should work as well.

Valentin Svelland

Friday 18 July 2003 6:23:55 am

I've gone around in circles on this one. Can't figure out why this snippet won't work.. Can't really get the switch to work proper either..

{section name=contactinfo show=$content_version.data_map.contact_info.data_text}
<h2>Contact information:</h2>
{attribute_view_gui attribute=$content_version.data_map.contact_info}

{section-else}
<p>Shown for zero or empty vars</p>

{/section}

From this code the header "Contact information:" is always shown, even when there's no text whatsoever in the contact_info field..

Bjørn Kaarstein

Wednesday 23 July 2003 4:56:51 am

Found a solution! This goes for an image field in my article class.
An ordinary fetch around it of course...

{section name=artikler loop=$artikkel}

<table width="550" border="0" cellspacing="2" cellpadding="0">
<tr>{*Henter overskriftsfeltet fra artikkelklassen*}
<td valign="top" class="td1">{attribute_view_gui attribute=$:item.data_map.overskrift} </td>
</tr>
<tr>
<td valign="top" class="td2"><p>

{* Shows picture if it's present in article*}
{section show=ne($:item.data_map.bilde.content)}

<img src={$:item.data_map.bilde.content[original].full_path|ezurl} hspace="10" vspace="10" border=0 align=right>

{/section}

{*Henter innholdet fra XML-feltet i artikkelklassen*}
{attribute_view_gui attribute=$:item.data_map.innhold}

</p>
</td>
</tr>
</table>
{/section}

Regards Bjørn

Valentin Svelland

Wednesday 23 July 2003 6:41:45 am

Hope your way works for me too, and the reason why I can't get it to function here is my programming skills:

This won't work... Can't u see the bug?

{section show=ne($:item.data_map.tj_saksgang.content)}
<h2 class="tjenestebeskrivelse">Saksgang:</h2>
{attribute_view_gui attribute=$content_version.data_map.tj_saksgang}<br />
{/section}

or this...

{section show=ne($content_version.data_map.tj_saksgang)}
<h2 class="tjenestebeskrivelse">Saksgang:</h2>
{attribute_view_gui attribute=$content_version.data_map.tj_saksgang}<br />
{/section}

Selmah Maxim

Wednesday 23 July 2003 6:49:28 am

This work for me :

{section show=$:item.data_map.tj_saksgang.content}
<h2 class="tjenestebeskrivelse">Saksgang:</h2>
{attribute_view_gui attribute=$content_version.data_map.tj_saksgang}<br />
{/section}

also : (what i`m using)

{section show=$content_version.data_map.fax.content}
<label class="viewhead">{$content_version.data_map.fax.contentclass_attribute.name}</label>
<p>{$content_version.data_map.fax.content}</p><div class="labelbreak"></div>
{/section}

Paul Forsyth

Wednesday 23 July 2003 6:52:08 am

Generally you can check if the attributes .content field is empty or not.

For an xml data field you need to go further, e.g:

{section show=$content_version.data_map.my_field.content.is_empty|not}

Show me if not empty

{section-else}

Show me if empty
{/section}

Hope this helps

paul

Valentin Svelland

Wednesday 23 July 2003 7:00:14 am

Ok thanks both of you!! Just made it work with this code:

{section show=ne($node.data_map.contact_info.content.output.output_text)}
<h2 class="tjenestebeskrivelse">Contact information:</h2>
{attribute_view_gui attribute=$content_version.data_map.contact_info}<br />
{/section}

Hooray!! Think I'll get drunk and celebrate! :D Cheers!

Michael Bolien

Saturday 26 July 2003 12:27:02 pm

@Jan and Bard,

This is, why I mentioned that ez publish is illogical and bad documentated. You sit hour by hour for such a little thing which you do in php or perl in seconds. Here you must guess and trial and error.

This ne-thing is a not documented function, I never found something about in the SDK and what's about the syntax Paul suggested? Not documented either.

In general your documentation: you deal everyday with your system, you made it, you know every little thing about it and so is the documention. For ones who stand outside, the docs are incomprehensible.

Here I face my problems for being forced by my customers to admin all his complex sites with ez. ez wasn't made to do big sites. It is a complicated system for building simple sites.

But unfortunately I have to go on. Sorry - but I have to write this, because I spent six month to make a complex site run satisfactorily and it is still in parts under construction at last due changing the override behaviour.

Regards,
Michael

Graham Tillotson

Wednesday 24 September 2003 12:13:22 pm

I have to agree that the documentation on this should be clear. Please DO NOT suggest a way of doing something unless you know it works. I sat here for a hour trying to get the section methods working (the "preferred" way) and NOTHING worked. I changed over to the switch method and it works great.

DUO : CONSULTING
Web content management experts
www.duoconsulting.com