We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44406
    • 11 Posts
    Hi there,

    I'm trying to use nested snippets so that if there are no children then nothing is displayed.

    Within a Wayfinder chunk, this returns a value for each item:
    [[getChildCount? &parent=`[[+wf.docid]]`]]

    But this code always shows the ELSE output code and I think it's because I'm trying to run one snippet inside another:
    [[If? &subject=`[[getChildCount? &parent=`[[+wf.docid]]`]]` &operator=`NEQ` &operand=`0` &then=`
    
    <li[[+wf.id]][[+wf.classes]]>
      <h2>[[+wf.linktext]] .[[getChildCount? &parent=`[[+wf.docid]]`]]</h2>
    
            <ul class="block-list group">
              [[msProducts? &parents=`[[+wf.docid]]` &limit=`4`]]
            </ul>
    
            [[If? &subject=`[[getChildCount? &parent=`[[+wf.docid]]`]]` &operator=`GT` &operand=`4` &then=`<a href="[[+wf.link]]" [[+wf.attributes]]>View all [[+wf.linktext]]</a>`]]
    
    </li>
    
    ` &else=`[[+wf.linktext]] [[getChildCount? &parent=`[[+wf.docid]]`]]
    
    `]]

    It doesn't seem to matter whether I use NEQ or GT.

    Do I need to create a new snippet that uses runSnippet and if so, how would this work?

    Thanks,

    David
      • 3749
      • 24,544 Posts
      You might try calling getChildCount uncached:

      [[!getChildCount ... ]]

      That might delay the processing until the page is rendered.

      The way you're doing this is likely to be fairly slow, since all the tags will be processed whether they are used or not.

      I would be tempted to put all that logic in a snippet called getOuput, and just have one uncached snippet tag:

      [[!getOutput? &parent=`[[+wf.docId]]` &wfLinkText=`[[+wf.linktext]]` &wfClasses=`'[[+wf.classes]]`  &wfId=`[[+wf.id]]` ]]


      Then have the snippet create all the output and return it.
        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
        • 44406
        • 11 Posts
        If I set the first ChildCount to uncached, then the &else statement is still triggered:
        [[If? &subject=`[[!getChildCount? &parent=`[[+wf.docid]]`]]` &operator=`GT` &operand=`0` &then=`

        Unfortunately, I don't know enough PHP to write a getOutput snippet despite reading the runSnippet documentation.

        Thanks,

        David
          • 21078
          • 77 Posts
          Hey David,

          wouldn't it be much easer to use &rowTpl and &parentRowTpl in your Wayfinder call to differ between the output of container with/without children?

          Have a look at the documentation and examples:
          http://rtfm.modx.com/display/ADDON/Wayfinder#Wayfinder-TemplateParameters

          Regards,
          Chris
            L.net Web Solutions
            Professional webdesign and development with MODX and WordPress.
            • 3749
            • 24,544 Posts
            Quote from: davidsalmon at Jul 19, 2013, 05:20 AM
            If I set the first ChildCount to uncached, then the &else statement is still triggered:
            [[If? &subject=`[[!getChildCount? &parent=`[[+wf.docid]]`]]` &operator=`GT` &operand=`0` &then=`

            Unfortunately, I don't know enough PHP to write a getOutput snippet despite reading the runSnippet documentation.

            First, see Chris's post just above, it may solve everything.

            What I was suggesting wouldn't involve runSnippet(), just a custom snippet. I'm not sure it would work, though, because it would need the ID of the Resource being processed and I'm not sure that would be available at the time Wayfinder is processing the resource.
              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