We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8489
    • 90 Posts
    I want to call a parent from within a child and want to exclude the other parents without using &excludeDocs or &includeDocs and without using the id of the Head Parent in &startId.
    So for example in the context from child 3.1 I would like to have a link to Sub Parent 01

    Head Parent

    Sub Parent 01
    - child 1.1
    - child 1.1
    - child 3.1
    - child 4.1

    Sub Parent 02
    - child 1.2
    - child 2.2
    - child 3.2
    - child 4.2

    I have this on the moment but on all the childs of Sub Parent 02 it calls Sub Parent 01

    [[Wayfinder?
             &startId=`[[UltimateParent]]`
             &rowTpl=`countTplRow`
             &limit=`1`
             &level=`1`
           ]]
      • 22427
      • 793 Posts
      Try this call:
      [[Wayfinder?
               &startId=`[[UltimateParent? &topLevel=`2`]]`
               &hideSubMenus=`1`
               &rowTpl=`countTplRow`
               &limit=`1`
               &level=`1`
             ]]
        • 8489
        • 90 Posts
        ottogal, Thanks for your reply I tried your code but it makes no difference.
        The child’s of Sub Parent 02 still calls Sub Parent 01
          • 18373 ☆ A M B ☆
          • 3,141 Posts
          [[~[[*parent]]]]




          If you also want a pagetitle or something similar, you could use getResourceField, or write your own lil’ snippet... this one takes in the chunk, and puts the resource fields as placeholders.

          $parent = $modx->resource->getOne('Parent');
          return $modx->getChunk('countTplRow',$parent->toArray());

          (of course, some error checking (is there a parent? does the chunk exist?) would be convenient)

          Somewhat related (a snippet to get the children, instead of the parent): http://www.markhamstra.nl/modx/general/tips-tricks-tutorials/get-children-snippet-and-learn-xpdo.html
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
            • 8489
            • 90 Posts
            Thanks Mark H. for your reply, I tried the code but it is calling the first file (Home)

            [[Wayfinder?
                     &startId=`[[~[[*parent]]]]`
                     &rowTpl=`countTplRow`
                     &limit=`1`
                     &level=`1`
                   ]]



            Home

            Head Parent

            Sub Parent 01
            - child 1.1
            - child 1.1
            - child 3.1
            - child 4.1

            Sub Parent 02
            - child 1.2
            - child 2.2
            - child 3.2
            - child 4.2
              • 18373 ☆ A M B ☆
              • 3,141 Posts
              No...

              Don’t put it in Wayfinder.

              [[~[[*parent]]]] exists of two parts:
              [[*parent]] is filled with the ID of the parent
              [[~ ... ]] makes a link to the ID passed to it.

              So [[~[[*parent]]]] makes a link to the parent (the href part). That’s what you’re looking for, right?


              The other code i posted needs to go into a snippet of its own which you put instead of the wayfinder call: [[snippetname]] (no properties needed)
                Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                • 8489
                • 90 Posts
                Thanks Mark H.! learning new stuff here, got it working now!

                Snippet: callParent

                $parent = $modx->resource->getOne('Parent');
                return $modx->getChunk('countTplRow',$parent->toArray());


                Chunk: countTplRow

                <a href="[[~[[*parent]]]]" title="[[+menutitle]]" class="overzicht"><span>Overzicht alle [[+menutitle]] / Aantal (<strong>[[getChildCount? &parent=`[[+id]]`]]</strong>)</span></a>


                Snippet: getChildCount

                $count = 0;
                $parent = isset($parent) ? (integer) $parent : 0;
                if ($parent > 0) {
                    $criteria = array(
                        'parent' => $parent,
                        'deleted' => false,
                        'published' => true,
                    );
                    $count = $modx->getCount('modResource', $criteria);
                }
                return (string) $count;
                  • 22427
                  • 793 Posts
                  ... you could use getResourceField ...
                  For example in this way:
                  <a href="[[~[[!UltimateParent? &top=`2` &topLevel=`1`]]]]">
                  [[!getResourceField? &id=`[[!UltimateParent? &top=`2` &topLevel=`1`]]` &field=`pagetitle`]]
                  </a>
                  Most likely you would have to adjust the values of [tt]&top[/tt] and [tt]&topLevel[/tt] to meet your resources tree.