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

    I’ve been trying to create a multi-select template variable that lists all the children of the current document. The code below works but I want to replace the hardcoded ’7’ with the id of the page being edited.

    @eval global $modx; $childArr = $modx->getDocumentChildren(7); foreach($childArr as $child){$opArr[]=$child['pagetitle']."==".$child['id'];} return $opArr;


    I though that I should just be able to use $modx->documentIdentifier to get the current id but it appears that the document object is not available when generating a TV.

    I’ve also tried moving the code to a snippet which, when called by the template, returns the correct array.

    If I run the snippet via
    @EVAL global $modx; return $modx->runSnippet('select_children');
    then the array returned is the children of the root document.

    Is there anyway to get the current doc ID in this situation?
      • 29774
      • 386 Posts
      $modx->documentIdentifier will only return the id of a document being viewed on the front end. Inside the manager you can use $_GET[’id’]
        Snippets: GoogleMap | FileDetails | Related Plugin: SSL
        • 28580
        • 24 Posts
        Excellent. That sorted it.

        Thanks