public function refine($formID)
 {
     $contents = $this->template;
     $s = '/(<perch:form[^>]*id="' . $formID . '"[^>]*>)(?:(?!perch:form).*)(?:<\\/perch:form>)/s';
     preg_match_all($s, $contents, $match, PREG_SET_ORDER);
     if (PerchUtil::count($match)) {
         $this->template = $match[0][0];
         $tag = new PerchXMLTag($match[0][1]);
         $this->form_tag_attributes = $tag->get_attributes();
     }
 }
 public function render_layouts($html, $vars = array())
 {
     if (strpos($html, 'perch:layout') !== false) {
         $s = '/<perch:layout[^>]*>/';
         $count = preg_match_all($s, $html, $matches);
         $renderer = $this->layout_renderer;
         if ($count > 0) {
             if (is_array($matches[0])) {
                 foreach ($matches[0] as $match) {
                     $Tag = new PerchXMLTag($match);
                     $attrs = $Tag->get_attributes();
                     if (is_array($vars)) {
                         $vars = array_merge($vars, $attrs);
                     } else {
                         $vars = $attrs;
                     }
                     $out = $renderer($Tag->path(), $vars, true);
                     $html = str_replace($match, $out, $html);
                 }
             }
         }
     }
     return $html;
 }