/** * Loads a template given any path. The path is in the format componentPart://componentName/viewName/layoutName, * for example * site:com_example/items/default * admin:com_example/items/default_subtemplate * auto:com_example/things/chair * any:com_example/invoices/printpreview * * @param string $uri The template path * @param array $forceParams A hash array of variables to be extracted in the local scope of the template file * @param callable $callback A method to post-process the evaluated view template * * @return string The output of the template * * @throws \Exception When the layout file is not found */ public function loadAnyTemplate($uri = '', $forceParams = array(), $callback = null) { if (isset($this->viewTemplateAliases[$uri])) { $uri = $this->viewTemplateAliases[$uri]; } $layoutTemplate = $this->getLayoutTemplate(); $extraPaths = array(); if (!empty($this->templatePaths)) { $extraPaths = $this->templatePaths; } // First get the raw view template path $path = $this->viewFinder->resolveUriToPath($uri, $layoutTemplate, $extraPaths); // Now get the parsed view template path $this->_tempFilePath = $this->getEngine($path)->get($path, $forceParams); // We will keep track of the amount of views being rendered so we can flush // the section after the complete rendering operation is done. This will // clear out the sections for any separate views that may be rendered. $this->incrementRender(); // Get the evaluated template $contents = $this->evaluateTemplate($forceParams); // Once we've finished rendering the view, we'll decrement the render count // so that each sections get flushed out next time a view is created and // no old sections are staying around in the memory of an environment. $this->decrementRender(); $response = isset($callback) ? $callback($this, $contents) : null; if (!is_null($response)) { $contents = $response; } // Once we have the contents of the view, we will flush the sections if we are // done rendering all views so that there is nothing left hanging over when // another view gets rendered in the future by the application developer. $this->flushSectionsIfDoneRendering(); return $contents; }