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

    I’m looking for a way to get not just the ID, but the title of the ultimate parent of the current Document. This means I’d probably have to call the snippet from PHP myself? Not sure where to do that. Are there som API functions I missed?

    Thank you

    Philip Whitfield
      • 5340
      • 1,624 Posts
      my solution

      create a snippet and modify the following code to fit your needs

      <?php
      $parent = $modx->runSnippet(
              "UltimateParent",
              array(
                  "topLevel" => 2
              )
      );

      $atvs = array(’pagetitle’,’longtitle’);
      $tvs = $modx->getTemplateVarOutput($atvs,$parent);

      echo $tvs[’pagetitle’];
      // OR
      //echo $tvs[’longtitle’];
      ?>

      In my case I used topLevel=2. You can use whatever you need.
        • 36592
        • 970 Posts
        If you can get the id of your target document, you can get pagetitle of that document using getField snippet.
        You can try something like...
        [!getField? &docid=`[[UltimateParent? &toplevel=`2`]]` &field=`pagetitle`!]
        
          • 5340
          • 1,624 Posts
          nice to know that there is a simpler way. Thx
            • 31043
            • 2 Posts
            Perfect. The GetField snippet did the job.
            Thanks for your quick answers. (Topic closed)

            This discussion is closed to further replies. Keep calm and carry on.