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

    I want to write a little snippet and need some help. This snippet - you may call it LinkToThis - will read IDs of documents written in a TV and build a list of links. Sure, the is Related snippet but this relies on Ditto and thats why I didn´t get it running on a single document. And you cant´t change the order of the linked documents individually when the sorting rule is set.

    Here is the code with my question problem included wink

    $output = '<ul>';
        $vars = $modx->getTemplateVarOutput('verweis', $modx->documentIdentifier,'1');
        $vary = explode(",",$vars['verweis']);
        for($n=0;$n<sizeof($vary);$n++) {
       $output .=  '<li><a href="'.$modx->makeUrl($vary[$n]).'">how-do-i-get-the-pagetitle-of-the-linked-document?</a></li>';
        }
    $output.= '</ul>';
    
    return $output;
    


    So how can I get the titles of the linked document? Any help would be appreciated. And of course I will publish the completed snippet.

    Mazso
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Use the getPageInfo function; it returns an array containing the fields requested.
      $parent = $modx->getPageInfo($vary[$n], 1, 'parent');
      $title = $modx->getPageInfo($parent['parent'], 1, 'pagetitle');
         $output .=  '<li><a href="'.$modx->makeUrl($vary[$n]).'">$title['pagetitle']</a></li>';
      


      http://wiki.modxcms.com/index.php/API:getPageInfo

      I’m sure there’s a twisty SQL query that could do it all in one line, but this way doesn’t make my head hurt.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 18830
        • 161 Posts
        Thank you, Sottwell. That helps me.

        I changed your code a little bit because in this way it returned the parent´s pagetitle. Here is what I did:

        $title = $modx->getPageInfo($vary[$n], 1, 'pagetitle');
        $output .=  '<li><a href="'.$modx->makeUrl($vary[$n]).'">'.$title['pagetitle'].'</a></li>';
        


        I hope, this won´t give you any headaches. wink

        Mazso
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Ok, I missed the part where the TV contained a list of parents, in the sense of Wayfinder parent parameter parents!
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 18830
            • 161 Posts
            LinkToThis 0.1 is in the repository.