/** * Render the presentation and return the result. * * @param AgaviTemplateLayer The template layer to render. * @param array The template variables. * @param array The slots. * @param array Associative array of additional assigns. * * @return string A rendered result. * * @author David Zülke <*****@*****.**> * @since 1.0.6 */ public function render(AgaviTemplateLayer $layer, array &$attributes = array(), array &$slots = array(), array &$moreAssigns = array()) { $twig = $this->getEngine(); $path = $layer->getResourceStreamIdentifier(); if ($layer instanceof AgaviFileTemplateLayer) { $pathinfo = pathinfo($path); // set the directory the template is in as the first path to load from, and the directory set on the layer second // that way, including another template inside this template will look at e.g. a locale subdirectory first before falling back to the originally defined folder $paths = array($pathinfo['dirname'], $layer->getParameter('directory')); // also allow loading from the main template dir by default, and any other directories the user has set through configuration foreach ((array) $this->getParameter('template_dirs', array(AgaviConfig::get('core.template_dir'))) as $dir) { $paths[] = $dir; } $twig->setLoader(new Twig_Loader_Filesystem($paths)); $source = $pathinfo['basename']; } else { // a stream template or whatever; either way, it's something Twig can't load directly :S $twig->setLoader(new Twig_Loader_String()); $source = file_get_contents($path); } $template = $twig->loadTemplate($source); $data = array(); // template vars if ($this->extractVars) { foreach ($attributes as $name => $value) { $data[$name] = $value; } } else { $data[$this->varName] = $attributes; } // slots $data[$this->slotsVarName] = $slots; // dynamic assigns (global ones were set in getEngine()) $finalMoreAssigns = self::buildMoreAssigns($moreAssigns, $this->moreAssignNames); foreach ($finalMoreAssigns as $key => $value) { $data[$key] = $value; } return $template->render($data); }