Hide empty sections with PHx

on 13-Sep-2009 | Comments ( 8 ) Tags: Evolution

Use the following code to switch off parts of your website when no content is available. This comes in handy when those parts of your website have a background color.

[+phx:if=`[*side-content:len*]`:gt=`10`:then=`
    <div id="sideContentWithBgColor">
        [*side-content*]
    </div>
`:else=``+]

 

Do you know other ways to do this in modx?

Write a comment

  • Required fields are marked with *.

If you have trouble reading the code, click on the code itself to generate a new random code.
 
Dimmy
Posts: 4
Comment
small error i think
Reply #8 on : Sat January 23, 2010, 07:49:26
the call should be like this:


the :len should be outside the if statement, it works inside but that it needs to pars it double and the else is not needed if else is empty.
Last Edit: January 23, 2010, 15:56:37 by cipa  
cipa
Posts: 4
Comment
Re: Hide empty sections with PHx
Reply #7 on : Sat January 23, 2010, 16:02:40
@Dimmy
1. Can you post an example with :len outside the if. If you did it was automatically removed.

2. I always leave the else when coding. It's kind of a standard for readability and it's easier to update your code if something needs to be done in the else part
manu
Posts: 4
Comment
Re: Hide empty sections with PHx
Reply #6 on : Sun February 07, 2010, 05:52:45
phx:if=`TV`:is=``:then=``:else=`my html`

i use empty `` to check of emptiness
Last Edit: February 07, 2010, 07:42:40 by cipa  
cipa
Posts: 4
Comment
Re: Hide empty sections with PHx
Reply #5 on : Sun February 07, 2010, 07:44:32
Hi Manu,
I prefer the len method because sometimes users will leave empty bold tags or similar in the rich textareas.

Thx for the commment
ziya
Posts: 4
Comment
Re: Hide empty sections with PHx
Reply #4 on : Thu January 27, 2011, 06:20:01
sorry, but where to place this code.
cipa
Posts: 4
Comment
Re: Hide empty sections with PHx
Reply #3 on : Thu January 27, 2011, 13:20:38
In your Ditto call or in the template.
I don't think it works in Wayfinder
EsperMedia
Posts: 4
Comment
Check if empty
Reply #2 on : Tue April 24, 2012, 14:09:24
phx:if=`TV`:ne=``:then=`my html`
cipa
Posts: 4
Comment
Re: Hide empty sections with PHx
Reply #1 on : Tue April 24, 2012, 16:27:12
What if you have  &nbsp? I think a len solution is more safe for content areas
Last Edit: April 24, 2012, 16:27:56 by cipa  

Quick modx Evolution Tags

  • cached [[snippet]] or uncached [!snippet!]
  • {{chunk}}
  • [+placeholder+]
  • [*resourceField/TV*]
  • [^timing^]
  • [~link~]

Quick modx Revolution Tags

  • [[snippet]]
  • [[$chunk]]
  • [[+placeholder]]
  • [[*resourceField/TV]]
  • [[~link]]
  • [^timing^]
  • [[++systemSetting]]
  • [[%languageStringKey]]
  • all tags can be called un-cached like: [[! snippet]]

Timing Tags (Evo and Revo)

  • [^qt^] - Query time
  • [^q^] - Query count
  • [^p^] - Parse time
  • [^t^] - Total time
  • [^s^] - Source
© modxRULES! 2009-2014