Ejemplo n.º 1
0
 /**
  * Replace <ktml:content> with the view content
  *
  * @param string $text  The text to parse
  * @param TemplateInterface $template A template object
  * @return void
  */
 public function filter(&$text, TemplateInterface $template)
 {
     $matches = array();
     if (preg_match_all('#<ktml:content(.*)>#siU', $text, $matches)) {
         foreach ($matches[0] as $key => $match) {
             $attributes = array_merge($this->_attributes, $this->parseAttributes($matches[1][$key]));
             $content = $template->content();
             if (!empty($content)) {
                 //If attributes are set but no decorator set it to <div>
                 $element = null;
                 if (!empty($attributes)) {
                     if (isset($attributes['decorator'])) {
                         $element = trim(strtolower($attributes['decorator']));
                         unset($attributes['decorator']);
                     } else {
                         $element = 'div';
                     }
                 }
                 //Do not decorate if no element is defined
                 if ($element) {
                     $attribs = '';
                     if (!empty($attributes)) {
                         $attribs = ' ' . $this->buildAttributes($attributes);
                     }
                     $content = sprintf('<' . $element . '%s>%s</' . $element . '>', $attribs, PHP_EOL . $content . PHP_EOL);
                 }
             }
             //Remove the tags
             $text = str_replace($match, $content, $text);
         }
     }
 }