We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36977
    • 36 Posts
    Hello! I'm pretty new to modx (Revolution 2.2.14), have only made a few basic sites so excuse me if this is really fundamental and obvious.. but...

    I want to use the IF extra with an inline snippet call, which has another inline snippet call!

    Is this possible? Or do I need to move the logic to one snippet? Not got much experience specifically with PHP but willing to learn if that's the best way!

    This is what I'm trying to do....

    [[!If?
    &subject=`[[getChildCount? &parent=`[[*id]]`]]`
    &operator=`LT`
    &operand=`3`
    &then=`[[Wayfinder? &level=`1` &rowTpl=`rowTplMenuGridHalf` &outerTpl=`outerTplGridMenu`]]'
    &else='[[Wayfinder? &level=`1` &rowTpl=`rowTplMenuGridThird` &outerTpl=`outerTplGridMenu`]]'
    ]]

    And its failing as soon as I add the snippet in the subject.
      • 3749
      • 24,544 Posts
      I Think I would do it this way:

      [[!SetRowTpl]]
      [[Wayfinder? &level=`1` &rowTpl=`[[+MyrowTpl]]` &outerTpl=`outerTplGridMenu`]]



      /* SetRowTpl snippet */
      $parentId = $modx->resource->get('Parent');
      
      $childCount = $modx->getCount('modResource', array('parent' => $parentId));
      
      $output = $childCount < 3) ? 'rowTplMenuGridHalf' : 'rowTplMenuGridThird';
      
      $modx->setPlaceholder('MyrowTpl', $output);
      
      return '';


      The call to SetRowTpl has to be above the Wayfinder tag so it will be parsed first.



        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
        • 36977
        • 36 Posts
        Thankyou! I'll try that approach smiley
          • 36977
          • 36 Posts
          OK, so encountering a problem when running that snippet. Firstly, it was failing altogether and I realised there was a missing bracket:

          $output = ($childCount < 3) ? 'rowTplMenuGridHalf' : 'rowTplMenuGridThird';

          So now the snippet doesn't fail, but its not working either. It doesn't seem to be setting/using (not sure which) the variable $output correctly. When I use the wayfinder call with that snippet its not calling the rowTpl function.

            • 36977
            • 36 Posts
            I've actually just gone for a two template approach in the end. Would be interested to know the issue but obv not a priority! Thanks