Share » Forums » Setup & design » Ignore <br> tag?

Ignore <br> tag?

Ignore <br> tag?

Wednesday 27 August 2003 2:16:53 pm - 3 replies

Modified on Wednesday 27 August 2003 2:17:11 pm by Douglas Johnson

Author Message

Alex Jones

Wednesday 27 August 2003 2:26:18 pm

Try:

{section show=eq($:item.data_map.header.content,'')} {* Check the header field for content - if it is empty print this (in this case nothing is output): *}

{section-else} {* Else print header surrounded by breaks *}
<br>{attribute_view_gui attribute = $content_version.data_map.header}</br>
{/section}

Note, this could be shorter using 'ne' (not equal) in place of the 'eq' (equal) and eliminating the {section-else}, but I wrote it like this so you could have an example of how to display different things depending on whether or not a field has a value.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Douglas Johnson

Thursday 28 August 2003 7:29:49 am

First I would like to thank you for your response. Without help from people like you, I would be out of a job.

The "section show=eq($:item.data_map.header.content,'')}" Thing did not work. Even if there wasn't any content, the <br> tag was still shown in the browser. I want to skip the line break if there is no content to be displayed. I'm begining to think this is not possible.

Also, how do I check for the existance of an image?

Alex Jones

Thursday 28 August 2003 7:53:31 am

No problem, we're all in the same boat! I've had a ton of help from other developers. :)

I'm not sure why the code I provided didn't work. Is your header text or an image? Also, have you tried looking at the attributes of the header? It might help you get an idea of what information you can detect for your show statement. Try: {$:item.data_map.header|attribute(show)} or {$:item.data_map|attribute(show)}

Here is some code that I am actually using in my templates to choose between possible images:

{section show=eq($:item.data_map.image,'')}
{attribute_view_gui attribute=$:item.data_map.image_1 image_class=proportionalmedium}
{section-else}
{attribute_view_gui attribute=$:item.data_map.image image_class=proportionalmedium}
{/section}

This code is detecting which image is available to display. I need the check as I am fetching several different types of class, one of which has multiple images (thus the 'image_1') while most only have a single image (thus just 'image').

So, I detect whether or not a field of 'image' contains any data. If it doesn't exist, or if it is empty it returns nothing and thus matches the show statement (specifically the '') so I display 'image_'1. The section-else displays 'image'.

Note: 'proportionalmedium' is a custom image class.

I hope this helps,

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu