We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21419
    • 84 Posts
    I’m able to generate the correct child in an array using either my php or Brunos’s. I am just unable to figure out how to get the data from that array to format as a number rather than the string "Array ( [62] => 62 ) 1"

    Sort of losing my mind over this. It’s right there, but I’m too dumb to figure it out. LOL
      • 4310
      • 2,310 Posts
      Here’s something I’ve used before :
      <?php
      $pid = $modx->documentIdentifier;
      $allChildren = $modx->getAllChildren($id= $pid, $sort= 'menuindex', $dir= 'ASC', $fields= 'id');
      $firstChild =  $allChildren[0]['id'];
      return $firstChild ;
      ?>

      It will return the id of the first child document.
        • 21419
        • 84 Posts
        BUNK58! Thank you! That is it!! Works perfectly.

        Thank you and thanks to all who contributed.
          • 4310
          • 2,310 Posts
          laugh
            • 25429
            • 32 Posts
            I created a snippet called firstChildId with the exact content bunk58 posted above yet when I call it with [[DittoFormat? &parents=`[[firstChildId]]` &display=`all` &tplItem=`modellItem` &group=`4` &sortBy=`menuindex` &sortDir=`ASC` &tplGroup=`modellGroup` ]] it gives me a parse error:

            « MODx Parse Error »MODx encountered the following error while attempting to parse the requested resource:
            « PHP Parse Error »
             
            PHP error debug
              Error: 	Invalid argument supplied for foreach()	 
              Error type/ Nr.: 	Warning - 2	 
              File: 	D:\xampplite\htdocs\ef\assets\snippets\ditto\classes\template.class.inc.php	 
              Line: 	50	 
              Line 50 source: 	foreach ($templates as $tplName=>$tpl) { 	 
             
            Parser timing
              MySQL: 	0.0662 s	(15 Requests)
              PHP: 	0.0823 s	 
              Total: 	0.1484 s


            What am I doing wrong?
              • 4310
              • 2,310 Posts
              Try alternating the caching of the snippet calls :
              [!DittoFormat? &parents=`[[firstChildId]]` &display=`all` &tplItem=`modellItem` &group=`4` &sortBy=`menuindex` &sortDir=`ASC` &tplGroup=`modellGroup`!]
                • 25429
                • 32 Posts
                Excellent! Thanks a bunch wink