elseif or switch statements hack with phx

on 22-Sep-2011 | Comments ( 5 ) Tags: Evolution, PHx

To emulate the elseif functionality we have to use the PHx or statement and a few PHx if statements.

Hopefully the code says it all:

[+phx:if=`[*id*]`:is=`1`:or:is=`2`:then=`
    [+phx:if=`[*id*]`:eq=`1`:then=`
        {{Chunk-1}}
    `:else=``+]
    [+phx:if=`[*id*]`:eq=`2`:then=`
        {{Chunk-2}}
    `:else=``+]
`:else=`
    {{OtherChunk}}
`+]

The above code can also be used for switch statements like functionality.

If you use this to check some value, that if changed the cache is not cleared, the page should not be cacheable. I mostly use this to check resource IDs or template IDs so the page can always be cached.

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.
 
Viktor
Posts: 3
Comment
Cool!
Reply #5 on : Fri September 30, 2011, 01:59:05
Thanks for useful blog!
Zaigham
Posts: 3
Comment
Re: elseif or switch statements hack with phx
Reply #4 on : Sun October 16, 2011, 08:32:55
In most circumstances for this to work properly, page should be un-cached.
cipa
Posts: 2
Comment
Re: elseif or switch statements hack with phx
Reply #3 on : Sun October 16, 2011, 08:38:29
True,
I mostly use this with resource ids or template ids. In these cases that page can be cached.

I'll add a note
Tanoloco
Posts: 3
Comment
Else not working for me :(
Reply #2 on : Fri October 28, 2011, 07:24:05
Very interesting! Thanks
Anyhow else statement is not working herw with revo 2.1.3

Trie a simple example:
1.
⌈⌈+phx:if=`this`:is=`this`:or:is=`that`:then=`YES`:else=`NO`+⌋⌋
OUT: YES (correct)

2.
⌈⌈+phx:if=`that`:is=`this`:or:is=`that`:then=`YES`:else=`NO`+⌋⌋
OUT: YES (correct)

3.
⌈⌈+phx:if=`foo`:is=`this`:or:is=`that`:then=`YES`:else=`NO`+⌋⌋
OUT: none!! (wrong expected NO)

Any help?
Thanks
cipa
Posts: 2
Comment
Re: elseif or switch statements hack with phx
Reply #1 on : Fri October 28, 2011, 19:20:01
This for MODX Evolution not MODX Revolution. You might be able to use IF for MODX Revolution.
Last Edit: October 28, 2011, 19:20:59 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