Forums / Developer / another newbie question: how do I perform selective displaying of content

another newbie question: how do I perform selective displaying of content

Author Message

Nick Woods

Thursday 29 January 2004 12:04:17 pm

Although an experienced developer in jsp and html I'm new to PHP and ezpublish.

I apologise that this is a very basic question but I'm still getting to grips with where ez stops and php starts.

What I want to do is test to see if a dataitem is populated or not, and if it is display some html

in other words, is a sort of 'jsp/php/ezpublish mixup language ' I'd do something like this
<% if( !node.object.data_map.body.equals("")) {
/* body is present, display it */
%>
<TR>
<TD>Here is the body</TD>
<td>{attribute_view_gui attribute=$node.object.data_map.body}</td>
</tr>
<% }; %>

As you can see from the example above, I want to eliminate rows in my table to save space. In the 'real' example there may be more than one row to omit, eg. I might have a blank row for spacing or an <HR> tag

ull if node.object.data_map.body is populated then include html such as a table row

Eirik Alfstad Johansen

Friday 30 January 2004 1:12:48 am

Hi Nick,

Check out the section template function and the show parameter:

http://www.ez.no/ez_publish/documentation/development/libraries/ez_template/functions/section

Sincerely,

Eirik Johansen

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Nick Woods

Friday 30 January 2004 5:23:06 am

Thanks Eirik, it looks like all i have to do is something like this. I'm assuming that the 'body' field in my example will be null if it has no data, otheriwse I need to find another way of doing it

{section name="body" show=$node.object.data_map.body}
<tr><td>etc etc etc</td></tr>
{/section}

Eirik Alfstad Johansen

Friday 30 January 2004 5:45:12 am

Hi,

You might need to use some operator, depending on which datatype the body attribute is built upon. Read up on the is_set operator and other operators here:

http://ez.no/ez_publish/documentation/development/libraries/ez_template/operators/type_handling

Sincerely,

Eirik Johansen

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Nick Woods

Sunday 01 February 2004 3:53:27 am

After a lot of messing about I ended up with this for text fields (where intro is the name of my field) :-

{section show=ne($node.object.data_map.intro.content.output.output_text | trim | count_chars,0)}

and for images this seems to work :-

{let image_1_Content=$node.data_map.image_1.content}
{section show=$image_1_Content.is_valid}