We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25979
    • 178 Posts
    Hi, I tried UltimateParent but it has changed since evo. I could specify to find parent in one level only there but in revo I can only specify the top no matter how many levels between lies there.

    Is there any other way or I am missing sth?

    Would be grateful for help.

    Regards,

    Mike
      //Why use windows since there is a door?//
      • 1778
      • 659 Posts
      hello,
      [[*parent]] returns the imediate parent ID...
        • 25979
        • 178 Posts
        Thanks very much!

        Regards,
        Mike
          //Why use windows since there is a door?//
          • 25979
          • 178 Posts
          By any chance you know how can I check if resurce has any children?

          Regards,

          Mike
            //Why use windows since there is a door?//
            • 1778
            • 659 Posts
            Hi
            After a quick look at the API documentation you should find this :

            hasChildren (line 517)
            Checks to see if the Resource has children or not. Returns the number of children.

            return: The number of children of the Resource
            access: public
            integer hasChildren ()
            So you can write a little simple snippet to do the task and return if a resource has children or not, it returns the number of children so if it is 0 your resource is not a parent...
            Hope this helps
            Cheers
              • 25979
              • 178 Posts
              Thanks, I have seen this but was looking for ready soultion wink And I believe I found a piece of information it is obsolete in revo and will be deleted in the next version somewhere there.

              Regards,

              Mike
                //Why use windows since there is a door?//
                • 1778
                • 659 Posts
                Hi

                You can write a snippet like this, let say you call it "hasChildren"

                <?php
                $children=$modx->resource->hasChildren();
                  if($children>0){
                    //if you are here, the current doc has at least one child
                    // we set a placeholder called nbchildren with the number of children
                    $modx->setPlaceholder('nbchildren',$children);
                    return;
                  }
                  else{
                    // if we are here the doc has no children we display a message
                    $msg='This document has no child' ;
                    return $msg;
                  }
                  return;
                ?>​
                


                In your resource you can call this snippet like this [[!hasChildren]] and if you want to display the number of children you can add in your resource something like this

                [[!hasChildren]]  <!-- call the snippet, display the message if no child -->
                
                <h4>This doc has [[+nbchildren]] children</h4> <!-- display the number of children via using the placeholder -->
                
                <!-- Or you can also do this -->
                
                <h4>This doc has [[+nbchildren:gt=`1`:then=`[[+nbchildren]] children`:else=`[[+children]] child` ]]
                


                Or something like that...
                Hope this helps
                Cheers
                  • 25979
                  • 178 Posts
                  Thanks, that is precisely what I needed. I will just change the output and this is it!

                  Regards,

                  Mike
                    //Why use windows since there is a door?//
                    • 1778
                    • 659 Posts
                    Glad if it fit your goal smiley
                    Cheers
                      • 25979
                      • 178 Posts
                      Hi, I could use soome more help as it looks it doesn’t work for me.

                      Would it be possible to have sth like hasChildren snippet for evo?

                      If there are children display that chunk if not another one.

                      :)

                      Mike
                        //Why use windows since there is a door?//