Hide empty sections with PHx

on 13-Sep-2009 | Comments ( 4 ) 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: 2
Comment
small error i think
Reply #4 on : Sat January 23, 2010, 08: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, 16:56:37 by cipa  
cipa
Posts: 2
Comment
Re: Hide empty sections with PHx
Reply #3 on : Sat January 23, 2010, 17: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: 2
Comment
Re: Hide empty sections with PHx
Reply #2 on : Sun February 07, 2010, 06:52:45
phx:if=`TV`:is=``:then=``:else=`my html`

i use empty `` to check of emptiness
Last Edit: February 07, 2010, 08:42:40 by cipa  
cipa
Posts: 2
Comment
Re: Hide empty sections with PHx
Reply #1 on : Sun February 07, 2010, 08: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

Quick modx Evolution Tags

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

Quick modx Revolution Tags

  • cached [[snippet]] or uncached [[!snippet]]
  • cached [[$chunk]] or uncached [[!$chunk]]
  • [[+placeholder]]
  • cached [[*resourceField/TV]] or uncached [[!*resourceField/TV]]
  • no timing tag - must investigate
  • [[~link]]
  • [[++systemSetting]]
  • [[%languageStringKey]]
© modxRULES! 2009-2010