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

    I have created a snippet that goes through a documents children and generates the ’pagetitle’ for each one can anyone tell me how i can incorporate the childrensTV into this loop? (im using tv to store a thumbnail image for each child).

    heres my code so far:

    $main_id = 2;
    $current_id = $modx->documentObject[’id’];
    $child = $modx->getDocumentChildren($main_id,1,0,"*","");
    $code_out = ’’;

    $count = 0;

    foreach($child as $value){
    if(!$value[’hidemenu’]){
    if($value[’id’] == $current_id){
    //$code_out .= $value[’menutitle’];
    $code_out .= ’<p>’ . $value[’pagetitle’] . ’</p>’;
    }else{
    //$code_out .= $value[’menutitle’];
    $code_out .= ’<p>’ . $value[’pagetitle’] . ’</p>’;
    }
    }
    $count++;
    }

    echo $code_out;

    Cheers, Ash
      • 33992 ☆ A M B ☆
      • 455 Posts
      You can do it easily with more and more features by Ditto:
      like this:
      [!Ditto? &parents=` parent ID ` &tpl=`myTpl`!]
      
      myTpl:
      [+pagetitle+]
      [+a TV name+]


      But for getting TV values you should get it from site_tmplvar_contentvalues table
        God loves me. 【ツ】


        MODX.ir (Persian Support)

        Boplo.ir/modx/ (Persian)
        • 5340
        • 1,624 Posts
        Try

        $tvs = array(’tvname1’, ’tvname2’);
        $rTv = $modx->getTemplateVarOutput($tvs,$docId);

        access values using $rTv[’tvname1’] and $rTv[’tvname2’]
          • 4172
          • 5,888 Posts
          I would realy use Ditto for that, but you can try also this one:

          <?php
          $main_id = 2;
          $current_id = $modx->documentObject['id'];
          
          $tvidnames = array ('id', 'pagetitle', 'menutitle', 'yourTV');
          $parentid = $main_id;
          $child = $modx->getDocumentChildrenTVarOutput($parentid, $tvidnames, $published = 1, $docsort = "menuindex", $docsortdir = "ASC");
          
          $code_out = '';
          
          $count = 0;
          
          foreach ($child as $value)
          {
              if (!$value['hidemenu'])
              {
                  if ($value['id'] == $current_id)
                  {
                      //$code_out .= $value['menutitle'];
                      $code_out .= '<p>'.$value['pagetitle'].'</p>';
                  } else
                  {
                      //$code_out .= $value['menutitle'];
                      $code_out .= '<p>'.$value['pagetitle'].'</p>';
          			$code_out .= '<p>'.$value['yourTV'].'</p>';
                  }
              }
              $count++;
          }
          
          echo $code_out;
          
          ?>
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 2249
            • 60 Posts
            Thanks for all your replies, works a treat.

            Ash