Hiding empty <?UMBRACO_GETITEM /> Options
azzlack
Posted: Monday, April 14, 2008 11:54:09 AM

Rank: Devotee

Joined: 8/5/2007
Posts: 94
Location: Bergen, Norway
Is it possible to hide an umbraco item if it is empty?

I.e. on some pages this call <?UMBRACO_GETITEM field="secondaryText"/> returns nothing.
The div that it resides (SecondaryText) in has borders, but i dont want those borders to be show if there is nothing inside them.

I tried using jQuery like this:
Code:
$(document).ready(function(){
            if ( $("#SecondaryText").length < 1) {
                $("#SecondaryText").hide();
            }
        });


But then it does not hide it when it's empty. Setting it to ".length <= 1" hides it properly, but it also hides every instance of the div that contains only 1 element.

So apparently, Umbraco returns an element to the webpage, even if its empty.

Anyone knows how to work aorund this?


www.eyecatch.no
drobar
Posted: Monday, April 14, 2008 3:20:07 PM

Rank: Umbracoholic

Joined: 9/8/2006
Posts: 1,698
Location: KY, USA
To add logic to your code you'll need to use a macro. Templates are for markup, macros are for logic. Even though this seems like a trivial situation you'll want a macro that checks to see if the secondaryText property has any content. Then you would only display the div tags if there were content in the field.

cheers,
doug.

MVP 2007-2009 - Official Umbraco Trainer for North America - Percipient Studios
kalpa
Posted: Monday, April 14, 2008 6:51:33 PM

Rank: Fanatic

Joined: 7/19/2006
Posts: 492
Location: Göteborg, Sweden
Another option is to put the div tag in the insert before and insert after boxes found in the get-item dialog, then nothing will be added to your page if the parameter doesn't return any data...

// ;) Kalle

" - Yeah I'd like to share your point of view, as long as it's my view too... (http://www.d-a-d.dk/lyrics/pointofview)
drobar
Posted: Monday, April 14, 2008 6:58:03 PM

Rank: Umbracoholic

Joined: 9/8/2006
Posts: 1,698
Location: KY, USA
@Kalle... that's brilliant! Very nice solution. Obvious, too. I almost never use those extra fields for the GETITEM and forget they are there :blush:

cheers,
doug.

MVP 2007-2009 - Official Umbraco Trainer for North America - Percipient Studios
dawoe
Posted: Tuesday, April 15, 2008 10:16:49 AM

Rank: Aficionado

Joined: 1/19/2008
Posts: 170
Location: Belgium
drobar wrote:
@Kalle... that's brilliant! Very nice solution. Obvious, too. I almost never use those extra fields for the GETITEM and forget they are there :blush:

cheers,
doug.


I use these too for displaying a image with Imagegen. That way I avoid having the ugly Hello World picture :-). Downside is that I have long insertbefore and insterafter properties.

Converting a DotNetNuke site to Umbraco : Follow it here
azzlack
Posted: Wednesday, April 16, 2008 12:40:12 PM

Rank: Devotee

Joined: 8/5/2007
Posts: 94
Location: Bergen, Norway
Thanks both for your help!

One thing that I like about Umbraco are these pleasant surprises with useful features.

www.eyecatch.no
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.