We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12958
    • 9 Posts
    Hello, I tried to nest 2 if-conditions in a template, but this doesn`t seem to work, the second if-condition will be ignored - or is there any error in my syntax?

      
    [[!If? &subject=`[[*title]]` 
           &operator=`notempty` 
           &then=`do this` 
           &else=`
    
           [[!If? &subject=`[[*item]]` 
                  &operator=`notempty` 
                  &then=`do other stuff`]]
    
    `]]
    


    Would be very glad to receive some advice! Thanks!

      • 11858
      • 130 Posts
      I’d like to know if this is possible also...
        • 33968
        • 863 Posts
        You could try a custom snippet. Perhaps call it elseIf:
        <?php
        $output = '';
        
        if ($title) {
            $output = 'do this';
        } elseif ($item) {
            $output = 'do other stuff';
        }
        
        return $output;
        


        Then call it like this:
        [[!elseIf? &title=`[[*title]]` &item=`[[*item]]`]]
        
          • 12410
          • 353 Posts
          i use output modifiers for this. You may find this code useful:

          [[!*id:is=`3`:or=!*id:is=`24`:or=!*id:is=`35`:then=`[[!include? &file=`assets/templates/inc/newslisting.php`]]`:else=`[[!*id:is=`54`:or=!*id:is=`64`:or=!*id:is=`75`:then=`[[!include?&file=`assets/templates/inc/bloglisting.php]]`:else=`[[!include? &file=`assets/templates/inc/textContent.php]]`]]`]]  <!--no spaces in syntax-->


          Instead of id you would use *title or *pagetitle I expect. Logic would be similar maybe. Possibly useful to u! Bit convulated looking alkright though. smiley
          http://rtfm.modx.com/display/revolution20/Input+and+Output+Filters+%28Output+Modifiers%29
            • 12410
            • 353 Posts
            possibly this will work for you


            [[!*pagetitle:is=``:then=`this html`:else=`[[!*pagetitle:is=`something else`:then=`show other code`:else=`show this other stuff`]]`]] 
              • 28215
              • 4,149 Posts
              Nesting If calls will slow down your site, and is generally not a good practice. Better is to use a custom snippet, as Lucas suggested.
                shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                • 12410
                • 353 Posts
                Thanks - I wouldnt have a clue how to create a custom snippet for the above though. I'm still at experimental stage.

                I ended up using this code till I become more intelligent or something better comes along to switch body html based on resource id. I like the idea of using 1 template with conditionals than choosing different templates in the manager.

                [[!*id:is=`3`:or=!*id:is=`24`:or=!*id:is=`35`:or=!*id:is=`38`:or=!*id:is=`42`:or=!*id:is=`44`:or=!*id:is=`47`:or=!*id:is=`32`:then=`[[!include? &file=`assets/templates/inc/newslisting.php]]`]]
                
                [[!*id:is=`54`:or=!*id:is=`64`:or=!*id:is=`75`:then=`[[!include?&file=`assets/templates/inc/bloglisting.php]]`]]
                
                [[!*id:is=`56`:then=`[[!include?&file=`assets/templates/inc/contact.php]]`]]
                
                [[!*id:notequalto=`3`:and=!*id:notequalto=`24`:and=!*id:notequalto=`35`:and=!*id:notequalto=`54`:and=!*id:notequalto=`64`:and=!*id:notequalto=`75`:and=!*id:notequalto=`56`:and=!*id:notequalto=`38`:and=!*id:notequalto=`42`:and=!*id:notequalto=`44`:and=!*id:notequalto=`47`:and=!*id:notequalto=`32`:then=`[[!include?&file=`assets/templates/inc/textContent.php]]`]]<!-- OR breaks so use AND-->



                Ya its a rather simplistic approach smiley [ed. note: howster last edited this post 12 years, 5 months ago.]
                  • 22427
                  • 793 Posts
                  I'm always wondering why people so eagerly avoid to have more than one template. Concerning performance, isn't it much better than using so many modifiers?

                  Also, if you have to add a new resource, you would just have to assign the suiting template instead of going into the code and fiddling around with the id values for the modifiers...
                    • 12410
                    • 353 Posts
                    Yep I know what your saying but I suppose it can avoid confusion for some non IT savvy clients when they are adding content when there is only 1 template involved. Good to know how to use output modifiers anyway sure. If anyone knows a good snippet to handle else if conditional for IDs as above please let me know. Thanks
                      • 4172
                      • 5,888 Posts
                      you can put this into a dropdown-TV 'pagetype' as input-options:

                      newslisting||bloglisting||contact||textContent


                      and put this into your template:

                      [[!include?&file=`assets/templates/inc/[[*pagetype]].php]]`]]


                      then you can switch from page to page.
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!