We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12379
    • 460 Posts
    I’ve got a short snippet that places a chunk on a page depending on it’s parent. Doesn’t seem to work. I’ve got it outputting $parentID to try to figure out what’s going wrong but it displays "Array". Doesn’t output the chunk "{{medRectTop_calculators}}" when the docs parent is 385,386 or 387.

    <?php
    // Switches top medium rectangle ad depending on doc parent (for calculator pages)
    $parentID=$modx->getParent($id);
    if ( $parentID=="385" || $parentID=="386" || $parentID=="387" )
      $output="{{medRectTop_calculators}}";
    else
      $output="{{medRectTop}}";
    return "$output" . "$parentID";
    ?>
      Mostly harmless.
      • 4041
      • 788 Posts
      Give this one a try and see if it helps:

      <?php
      // Switches top medium rectangle ad depending on doc parent (for calculator pages)
      // comma seperated list of doc ids
      $parentIDs= array('385', '386', '387');
      
      // get the current documents parent
      $thisparent = $modx->documentObject['parent'];
      
      $output ='';
      if (in_array($thisparent, $parentIDs))
        $output .='{{medRectTop_calculators}}';
      else
        $output .='{{medRectTop}}';
      return $output;
      ?>
        xforum
        http://frsbuilders.net (under construction) forum for evolution
        • 12379
        • 460 Posts
        Thanks - that’s brilliant and, at the same time, depressing as it made me realise how much I’ve got to learn when it comes to php!

        Anyhow, had a good hard look at directory structure and decided to use the following instead:

        <?php
        // Switches top medium rectangle ad depending on doc parent (for calculator pages)
        
        // Run snippet
        $params['topLevel']=2;
        $ultParent=$modx->runSnippet('UltimateParent', $params);
        
        if ( $ultParent=="30" )
          $output="{{medRectTop_calculators}}";
        else
          $output="{{medRectTop}}";
        return "$output";
        ?>




          Mostly harmless.