Search code examples
modx-revolution

Modx revolution: Conditional loading of chunks into website


I employ a snippet to get the number of child elements, returning an integer:

[[!getChildCount? &id=`12345`]]

Depending on the result of this (zero or greater than zero), I want to load two different chunks into my website. Here is my "Modx-Pseudocode" of what I would like to achieve. Been fiddling for hours now and just can't find out about the right syntax. This is what I'd like to write inside the content field:

[[!If [[!getChildCount? &id=`45`]] > 0 
then=`[load_chunk_A]` 
else=`[load_chunk_B]`]]

Any hints of how this is properly expressed in Modx revolution?


Solution

  • Seems you are talking about IF extra that you should install, if you haven't already done it, to achieve your goal.

    [[!If?
    &subject=`[[!getChildCount? &id=`45`]]`
    &operator=`>`
    &operand=`0`
    &then=`[[!$chunk_A]]` 
    &else=`[[!$chunk_B]]`
    ]]