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.
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.
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.
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