Source of file Partial.php
Size: 1,418 Bytes - Last Modified: 2017-11-08T13:54:24+00:00
/home/travis/build/bluzphp/framework/src/View/Helper/Partial.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 | <?php /** * Bluz Framework Component * * @copyright Bluz PHP Team * @link https://github.com/bluzphp/framework */ declare(strict_types=1); namespace Bluz\View\Helper; use Bluz\View\View; use Bluz\View\ViewException; /** * Render partial file * * be careful, method rewrites the View variables with params * * @param string $__template * @param array $__params * * @return string * @throws ViewException */ return function ($__template, $__params = []) { /** * @var View $this */ $__file = null; if (file_exists($this->path . '/' . $__template)) { $__file = $this->path . '/' . $__template; } else { foreach ($this->partialPath as $__path) { if (file_exists($__path . '/' . $__template)) { $__file = $__path . '/' . $__template; break; } } } if (is_null($__file)) { throw new ViewException("Template '{$__template}' not found"); } if (count($__params)) { extract($__params, EXTR_SKIP); } ob_start(); try { include $__file; } catch (\Exception $e) { ob_end_clean(); throw new ViewException("Template '{$__template}' throw exception: " . $e->getMessage()); } return ob_get_clean(); }; |