protected function render_related($type, $opening_tag, $condition_contents, $exact_match, $template_contents, $content_vars, $index_in_group)
 {
     $Tag = new PerchXMLTag($opening_tag);
     $out = '';
     if ($Tag->suppress()) {
         return str_replace($exact_match, '', $template_contents);
     }
     if (is_array($content_vars) && isset($content_vars[$Tag->id()]) && PerchUtil::count($content_vars[$Tag->id()])) {
         if (!class_exists('PerchContent_Collections', false)) {
             include_once PERCH_CORE . '/runway/apps/content/PerchContent_Collections.class.php';
             include_once PERCH_CORE . '/runway/apps/content/PerchContent_Collection.class.php';
             include_once PERCH_CORE . '/runway/apps/content/PerchContent_CollectionItems.class.php';
             include_once PERCH_CORE . '/runway/apps/content/PerchContent_CollectionItem.class.php';
         }
         $Collections = $this->_get_cached_object('PerchContent_Collections');
         $value = $Collections->get_data_from_ids_runtime($Tag->collection(), $content_vars[$Tag->id()], $Tag->sort());
         $RelatedTemplate = new PerchTemplate(false, $this->namespace);
         $RelatedTemplate->load($condition_contents);
         if (PerchUtil::bool_val($Tag->scope_parent())) {
             $vars_for_cat = array();
             if (PerchUtil::count($content_vars)) {
                 foreach ($content_vars as $key => $val) {
                     if ($key != $Tag->id() && $key != 'itemJSON') {
                         $vars_for_cat['parent.' . $key] = $val;
                     }
                 }
             }
             $vars_for_cat = array_merge($vars_for_cat, $content_vars[$Tag->id()]);
             foreach ($value as &$item) {
                 $item = array_merge($item, $vars_for_cat);
             }
         }
         $out = $RelatedTemplate->render_group($value, true);
     } else {
         if (strpos($condition_contents, 'perch:noresults')) {
             $s = '/<perch:noresults[^>]*>(.*?)<\\/perch:noresults>/s';
             $count = preg_match_all($s, $condition_contents, $matches, PREG_SET_ORDER);
             if ($count > 0) {
                 foreach ($matches as $match) {
                     $out .= $match[1];
                 }
             }
         }
     }
     return str_replace($exact_match, $out, $template_contents);
 }