We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30703
    • 51 Posts
    I’m having trouble with the ’If’ Snippet, I can’t get it to output my chunks. The chunks work and so does the IF call, but when I use them together, I get nothing (No output for &then, or &else)

    My call is:

      [[!If?
        &subject=`[[!sortbyGET]]`
        &operator=`NEQ`
        &operand=`starrating`
        &then=`[[!$getResourcesByCategory]]`
        &else=`[[!$getResourcesByRating]]`
      ]]


    If I use the call below, it outputs the text I expect and the conditional works fine.

      [[!If?
        &subject=`[[!sortbyGET]]`
        &operator=`NEQ`
        &operand=`starrating`
        &then=`Sort by menuindex or publishedon`
        &else=`sort by star rating`
      ]]


    Also, if I call either of my chunks they output the text I need too.

    [[!$getResourcesByCategory]]
    
    [[!$getResourcesByRating]]
    


    is there something else I need to get my chunks to be called from the If conditional?

      Tom Dyer

      Designer/Animator/Web Developer - England, UK.
      http://www.bespokepixels.co.uk
      • 2740
      • 95 Posts
        • 30703
        • 51 Posts
        Thanks, I’ve gotten around it by writing my own snippet to do what I was trying to do with the If snippet:

        $output = $modx->parseChunk("getResourcesByCategory");
        
        if(isset($_GET['s']) && !empty($_GET['s']))
        {
          $sortby = $_GET['s'];
          
          if($sortby == "rating")
          {
            $output = $modx->parseChunk("getResourcesByRating");
          }
        }
        
        return $output;​
        


        That does the job nicely grin

          Tom Dyer

          Designer/Animator/Web Developer - England, UK.
          http://www.bespokepixels.co.uk
          • 30703
          • 51 Posts
          Did you try calling your chunks cached, rather than uncached? I can't remember why but I've had issues in the past, calling uncached tags inside uncached tags.. if that makes sense. Try alternating between cached and uncached tags when nesting them...

          [[!If?
            &subject=`[[!sortbyGET]]`
            &operator=`NEQ`
            &operand=`starrating`
            &then=`[[!$getResourcesByCategory]]`
            &else=`[[!$getResourcesByRating]]`
          ]]
          

            Tom Dyer

            Designer/Animator/Web Developer - England, UK.
            http://www.bespokepixels.co.uk