@param $template
@param array $vars

@throws \Throwable

@return mixed|string
182101
public function buildTemplate($template, array $vars = [])
    {
        // Заменяем переменные в шаблоне
        //$found_template[$key] = preg_replace(array_keys($vars_preg_replace), array_values($vars_preg_replace), $value);

        try {
            //$tmp = $this->getContainer()->get('twig')->createTemplate('{% spaceless %} ' . $template . ' {% endspaceless %}');
            //                     'cache' => new \Twig_Cache_Filesystem($this->getConnector()->getTempDir(), \Twig_Cache_Filesystem::FORCE_BYTECODE_INVALIDATION),
            $tmp = $this->getContainer()->get('twig')->createTemplate('{% spaceless %} ' . $template . ' {% endspaceless %}');

            if ($vars) {
                $result = $tmp->render($vars);
            } else {
                $result = $tmp->render($this->vars);
            }

            /*
            $loader = new \Twig_Loader_Array(array(
                'index.html' => '{% spaceless %}' . $template . '{% endspaceless %}',
            ));

            $twig = new \Twig_Environment($loader, array(
                'autoescape' => false,
                'debug' => false
            ));

            $result = $twig->render('index.html', $this->vars);
            */
        } catch (\Exception $e) {
            $result = '';
        }

        $result = str_replace([' x ', ' х ', '()', ' ,', ' .', '( )'], [' ', ' ', '', ',', '.', ''], $result);

        // Вырезаем незамененые переменные
        //$result = trim(preg_replace('/\{\{.*\}\}/im', ' ', $result));

        $result = trim($result, ',:');

        // Удалить два и более пробела
        $result = trim(preg_replace('/ {2,}/m', ' ', $result));

        return $result;
    }
661795
protected function makeResponse(string $template, array $vars = [])
    {
        if (request()->ajax()) {
            return $this->jsonOutput($vars);
        }

        return $this->renderOutput($template, $vars);
    }
589380
public function _render($template, $vars, $directOutput)
    {
        if (isset($vars['view'])) {
            throw new MisuseException('variable `view` is reserved for view');
        }
        $vars['view'] = $this;

        if (isset($vars['request'])) {
            throw new MisuseException('variable `request` is reserved for view');
        }
        $vars['request'] = isset($this->request) ? $this->request : null;

        return $this->renderer->render($template, $vars, $directOutput);
    }
411537
protected function expandTemplate($template, array $variables = null)
    {
        $expansionVars = $this->getConfig()->toArray();
        if ($variables) {
            $expansionVars = $variables + $expansionVars;
        }

        return $this->getUriTemplate()->expand($template, $expansionVars);
    }
801113
protected function loadTemplate( $path, array $vars = [] ) {
		try {
			return \Pressbooks\Utility\template( $path, $vars );
		} catch ( \Exception $e ) {
			if ( WP_DEBUG ) {
				return "File not found: {$path}";
			} else {
				return '';
			}
		}
	}
274223
public function renderTemplate(string $template, array $variables = []): string
    {
        return $this->renderTemplateString($this->getTemplate($template), $variables);
    }
667727
protected function tpl($template, array $values)
    {
        if((!isset($values['id']) || !$values['id']) && isset($values['name'])) {
            $values['id'] = sprintf('input-%s', $values['name']);
        }

        $buffer = $template;
        foreach($values as $key => $val) {
            $buffer = str_replace('{{' . $key . '}}', $val, $buffer);
        }
        
        // Cleaning up the remaining placeholders.
        $buffer = preg_replace('%\{\{[^}]*\}\}%', '', $buffer);
        
        return $buffer;
    }
644284
public function renderRaw($module, $theme, $template, array $vars = array())
    {
        // Save initial values before overriding theme
        $initialLayout = $this->layout;
        $initialModule = $this->module;
        $initialTheme = $this->theme;

        // Configure view with new values
        $this->setModule($module)
             ->setTheme($theme)
             ->disableLayout();

        $response = $this->render($template, $vars);

        // Restore initial values now
        $this->layout = $initialLayout;
        $this->module = $initialModule;
        $this->theme = $initialTheme;

        return $response;
    }
1259684
public function addTemplate($template, $vars = []) {
        $tpl = new Template($template, 'template-mail', 0);

        foreach ($vars as $key => $var) {
            $tpl->assign($key, $var);
        }

        $message = $tpl->show();
        array_push($this->_message, $message);
    }
1254762
public function render($templateFile, array $vars = [])
    {
        $this->getService('retriever')->setLocalVars($vars);
        return $this->getService('template')->render($templateFile, $vars);
    }
992665
protected function renderOutput(string $template, array $vars = [])
    {
        $tpl = $this->template . '.'. $template;

        if (view()->exists($tpl)) {
            return view($tpl, $vars)->render();
        }

        abort(404, "View named $tpl not exists.");
    }
934664
public function render($template, array $vars = array(), $cookies = array(), $domain = null)
    {
        $vars['__menu__'] = $this->getMenu();
        if(Config::getParam('profiling.enable')) {
            $vars['__profiling__'] = Inspector::getStats();
        }
        $domain = (null === $domain) ? $this->getDomain() : $domain;
        return $this->tpl->render($domain . $template, $vars, $cookies);
    }
881351
protected function getJSTemplateVars($vars)
    {
        if (is_array($vars)) {
            return $vars;
        }
        
        if ($this->hasMethod($vars)) {
            return $this->{$vars}();
        }
        
        return [];
    }
771855
protected function fetch($template = '', $vars = [], $config = [], $renderContent = false)
    {
        $this->beforeViewRender();

        return $this->view->fetch($template, $vars, $config, $renderContent);
    }
578508
protected function renderOutput(string $template, array $vars = [])
    {
        pageinfo([
            'categories' => $this->getCategories(),
            'navigation' => $this->makeNavigation(),
        ]);

        $tpl = $this->template.'.'.$template;

        if (view()->exists($this->template) and view()->exists($tpl)) {

            $mainblock = html_raw(view($tpl, $vars)->render());

            return view($this->template, compact('mainblock'))->render();
        }

        abort(404, "View named $tpl not exists.");
    }
796610
protected function resolveCompositeBinding($vars)
    {
        $keys = array_keys($vars);

        foreach ($this->compositeBindings as $binding) {
            if ($keys === $binding[0]) {
                $binder = $binding[1];
                $errorHandler = $binding[2];

                $callable = $this->getBindingCallable($binder, null);
                $r = $this->callBindingCallable($callable, $vars, $errorHandler, true);

                if (!is_array($r) || count($r) !== count($vars)) {
                    throw new Exception("Route-Model-Binding (composite-bind) : Return value should be an array and should be of the same count as the wildcards!");
                }

                // Combine the binding results with the keys
                return array_combine($keys, array_values($r));
            }
        }
    }
408242
protected function parseTemplate($variables = [], $template = null)
    {
        if (null === $template) $template = 'migration';
        $replacements = array_merge($variables, $this->templateVariables);
        return strtr(file_get_contents(dirname(__DIR__) . '/templates/' . $template . '.tpl'), $replacements);
    }