We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25287
    • 81 Posts
    Hi Jason,
    the tv. was my latest experiment (trial & error) to get some result. I thought it may be needed as per the getresources snippet.

    Mystery is now solved. I have the snippet working in another localhost site I’m experimenting with, and it worked there. Had that moment of realisation, IF snippet was not installed in the one I am currently working on. Extreme embarrasment. Shows I am a noob.

    For future reference the working code is:

    [[!If? &subject=`[[*Edition]]` &operator=`EQ` &operand=`Open` &then=`[[!If? &subject=`[[*format]]` &operator=`EQ` &operand=`panorama` &then=`[[$OpenPano]]` &else=`[[$OpenEd]]` ]]`]]

    Maybe someone else can learn from my mistake.

    Sorry to waste your time.
      • 2986
      • 5 Posts
      Quote from: outdoorsadv at Oct 26, 2010, 11:53 PM

      I am looking to us the IF snippet. What I am trying to do is check to see if a user group or role is logged in. If so I would like it to output a chunk. If not return nothing.

      This is what I have so far. It’s not working, any help would be appreciated.

      [[!If? &subject=`[[+modx.user.role]]` &operator=`==` &operand=`Members` &then=`[[$right_col_members]]` &else=``]]


      Did you figure this out? I’m trying to do much the same thing == show one content bit to users logged in and/or in a given role and something else to everyone else. Per the documentation the above and below seems correct, but I can’t get it work. I have successfully used the IF snippet conditional on other things, just haven’t been successful when it’s user role or login status related.

      [[!If?  
         &subject=`[[+modx.user.id]]`  
         &operator=`EQ`  
         &operand=`0`  
         &then=`( Please login to see details on xyz. )`  
         &else=`[[!$show chunk abc]]`  
      ]] 


      That was based on the example on the IF package page. I also tried isemtpty and isnull and checking role. In all cases, the result of the ELSE statement is displayed regardless of the user’s login or role status.

      [[!If?  
         &subject=`[[+modx.user.id]]`  
         &operator=`isempty`
         &then=`( Please login to see details on the current challenge. )` 
         &else=`[[!$rmhog awol tour challenge details]]`  
      ]] 
      
      and 
      
      [[!If?  
         &subject=`[[+modx.user.id]]`  
         &operator=`isnull`
         &then=`( Please login to see details on the current challenge. )`  
         &else=`[[!$rmhog awol tour challenge details]]`  
      ]] 
      
      and 
      
      [[!If? 
         &subject=`[[+modx.user.role]]` 
         &operator=`==` 
         &operand=`Members`
         &then=`[[!$rmhog awol tour challenge details]]`  
         &else=`( Please login to see details on the current challenge. )`  
      ]]
      

        • 28215
        • 4,149 Posts
        Try:

        [[!+modx.user.id:is=`0`:then=`( Please login to see details on xyz. )`:else=`[[!$show chunk abc]]`]]


        Also note that there is no [[+modx.user.role]].
          shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
          • 2986
          • 5 Posts
          Quote from: splittingred at Dec 20, 2010, 08:06 AM

          Try:

          [[!+modx.user.id:is=`0`:then=`( Please login to see details on xyz. )`:else=`[[!$show chunk abc]]`]]


          Also note that there is no [[+modx.user.role]].

          Thanks. So noted. Tried it, but I still must have something wrong. I’m trying by placing the call to one CHUNK from a resource page with the hope that that chuck will conditionally call another chunk if the user is logged on.
          [[!+modx.user.id:is=`0`:then=`( Please login to see a summary of the current tour challenges. )`:else=`[[!$rmhog awol tour challenge details]]`]]

          Still, getting the "else" result regardless of the user login status (and I’m using two different computers to test at the moment one with me logged in to the manager, the other with no logged in user).

          I did look back and the place where I have the actual [[IF]] bit working successfully is in a TEMPLATE because in that instance I’m using it to conditionally display data based on whether or not a particular template variable is populated or not.

          Can these conditional type statements not be used in chunks? Update: Tried first chunk code in a template, and called directly from within a resource page. Both trials returned the same results = the "else" info for both logged in and logged out users.
            • 2740
            • 95 Posts
            I’m trying test whether a resources TV image has been selected; the TV has no default image. My tpl from getResources (&includeTVs=`1` &processTVs=`1` set) is:

            <p>[[!If? &subject=`[[*mytv_pic]]` &operator=`empty` &then=`no pic` &else=`pic` ]]<a href="[[~[[+id]]]]" title="[[+pagetitle]]">[[+pagetitle]]</a></p>


            If no image has been selected ’pic’ should simply be displayed. However even on resources where mytv_pic has an image ’no pic’ is always displayed.

            Solution:

            <p>[[!If? &subject=`[[+tv.mytv_pic]]` &operator=`empty` &then=`no pic` &else=`pic` ]]<a href="[[~[[+id]]]]" title="[[+pagetitle]]">[[+pagetitle]]</a></p>


            Hope this is of use to anyone else struggling with TV’s and If.
              • 436 ☆ A M B ☆
              • 265 Posts
              Is it possible to use ElseIf using the IF snippet? The way this example works: http://en.wikipedia.org/wiki/Conditional_(programming)#Else_if
                MODX Ambassador for Thailand. Managing Director at Monogon, a web design and development studio based in Bangkok, Thailand. - Follow me on Twitter.
                • 3749
                • 24,544 Posts
                Quote from: Adam at May 24, 2011, 12:57 PM

                Is it possible to use ElseIf using the IF snippet? The way this example works: http://en.wikipedia.org/wiki/Conditional_(programming)#Else_if
                Not at this time. Can you describe what you’re trying to do? A custom snippet would probably be pretty simple.
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 28099
                  • 39 Posts
                  I’m trying to use this to determine what banner to present depending what section you are in. Say I want IDs 14-16 (14 is parent)to show a certain banner, I want 12 (parent) and 27-33 (children) to show another. All other pages show the default banner.

                  The following almost does it. The problem, though, is that the parents get excluded:
                  [[!If? &subject=`[[*parent]]` &operator=`eq` &operand=`12` &then=`[[$sub-banner-1]]`]]
                  [[!If? &subject=`[[*parent]]` &operator=`eq` &operand=`14` &then=`[[$sub-banner-2]]` &else=`[[$sub-banner-default]]`]]
                  




                  The other situation is that I end up with IDs 12 and 14 meet 2 criteria and then display 2 banners.
                  [[!If? &subject=`[[*id]]` &operator=`eq` &operand=`12` &then=`[[$sub-banner-1]]`]]
                  [[!If? &subject=`[[*id]]` &operator=`eq` &operand=`14` &then=`[[$sub-banner-2]]`]]
                  [[!If? &subject=`[[*parent]]` &operator=`eq` &operand=`12` &then=`[[$sub-banner-1]]` &else=`[[!If? &subject=`[[*parent]]` &operator=`eq` &operand=`14` &then=`[[$sub-banner-2]]` &else=`[[$sub-banner-default]]`]]`]]
                  


                  Nesting the calls results in the same as above:
                  [[!If? &subject=`[[*id]]` &operator=`eq` &operand=`12` &then=`[[$sub-banner-1]]` &else=`
                  [[!If? &subject=`[[*id]]` &operator=`eq` &operand=`14` &then=`[[$sub-banner-2]]` &else=`
                  [[!If? &subject=`[[*parent]]` &operator=`eq` &operand=`12` &then=`[[$sub-banner-1]]` &else=`
                  [[!If? &subject=`[[*parent]]` &operator=`eq` &operand=`14` &then=`[[$sub-banner-2]]` &else=`[[$sub-banner-default]]`]]`]]`]]`]]
                  



                  I know there are other ways to do what I am trying to do but i just want to see if I can do it with conditional statements.

                  The problem is with my own logic. Either it is not possible to meet all the conditions with this plugin or my logic is off and just haven’t thought of the right sequence or method.

                  Thanks in advance...
                    • 3749
                    • 24,544 Posts
                    I don’t think there’s an easy way to implement an elseif conditional with the if snippet and you’re using up processing time parsing the properties.

                    I would just do this (untested):

                    [[!ShowBanner]]


                    <?php
                    /* ShowBanner snippet */
                    
                    $pageId = $modx->resource->get('id');
                    
                    if ($id >=14 && $id  <=16) {
                        $chunk = '$sub-banner-1';
                    
                    } else if ($id == 12 || ($id => 27 && $id <=33) ) {
                        $chunk = '$sub-banner-2';
                    } else {
                        $chunk = '$sub-banner-default';
                    }
                    return $modx->getChunk($chunk);


                    Another way to go would be to create a radio option TV called BannerChunk with a default value of @INHERIT [[$sub-banner-default]].

                    Input Option Values: Banner1==[[$sub-banner-1]]||Banner2==[[$sub-banner-3]]||Default==[[$sub-banner-default]]

                    Then put [[*BannerChunk]] where you want the banner to appear.
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 33337
                      • 3,975 Posts
                      I am having a trouble using in_array operand, here is my call:

                      <br />[[!If?<br />   &subject=`[[*id]]`<br />   &operator=`in_array`<br />   &operand=`2,4`<br />   &then=`positive`<br />   &else=`Else`<br />   <br />&debug=`1`<br />]]<br />


                      But it output &else statement everytime.

                      Am I using wrong syntax for operand? docs define it as "comma delimited string"

                      Thanks.
                        Zaigham R - MODX Professional | Skype | Email | Twitter

                        Digging the interwebs for #MODX gems and bringing it to you. modx.link