We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26163
    • 43 Posts
    Hello,

    How to write the phx statement for this condition?

    if *id* is 1 then { {Chunk1} }:if *id* is 2 then { {Chunk2} }:if *id* is 3 then { {Chunk3} }:else { {Chunk4} }

    The code I wrote below did not work:
    [+phx:if=`[*id*]`:is=`1`:then=`{ {Chunk1} }`:if=`[*id*]`:is=`2`:then=`{ {Chunk2} }`:if=`[*id*]`:is=`3`:then=`{ {Chunk3} }`:else=`{ {Chunk4} }`+]
      • 4172
      • 5,888 Posts
      this would allways process all contents of all chunks.

      Here is another solution to get this done:

      Create a listbox-TV with input-options like:

      chunk1=={{chunk1}}||chunk2=={{chunk2}}||chunk3=={{chunk3}}||chunk4=={{chunk4}}


      and a default-value of:
       {{chunk4}}


      put the TV-tag
       [*yourTV*]
      of your listbox-TV into your Template
      now you can choose the chunk to use for that page (if you want a chunk, other than chunk4)

        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 26163
        • 43 Posts
        Hi Bruno17,

        Actually I am trying to call a css id instead of a chunk here. In my case, I have a situation where I need to call a css class depending upon the page id, eg if page id is 1 display #cssid1, if page id is 2, display #cssid2 else display #cssid4 etc. Sorry for not getting the question correct in the first place.

        Does phx do this?
          • 26163
          • 43 Posts
          Bruno17's solution absolutely worked fine for me. I am using his suggestion currently. I could include the css call in chunks and select a particular chunk for individual page, and works like a charm.

          Still want to know if phx can handle this.
            • 4172
            • 5,888 Posts
            well, you can try something like that:

            [*id:is=`1`:then=`{{chunk1}}`:else=`
            [*id:is=`2`:then=`{{chunk2}}`:else=`
            [*id:is=`3`:then=`{{chunk3}}`:else=`
            {{chunk4}}
            `*]
            `*]
            `*]


            you could also create a simple switch-snippet, somthing like that:
            https://forums.modx.com/thread/45396/help-formatting-a-phx-condtional-for-switching-classes#dis-post-262240

            [ed. note: Bruno17 last edited this post 14 years, 1 month ago.]
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Keep in mind that phx/output modifiers is a scripting language built in PHP, which is itself a scripting language. So the more complex your modifiers, the slower it's going to be. For anything more than one or two conditions, you're much better off with a snippet.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org