Phrozn\Site\View\Base::applyLayout PHP Method

applyLayout() protected method

Two step view is used. View to wrap is provided with content variable.
protected applyLayout ( string $content, array $vars ) : string
$content string View text to wrap into layout
$vars array List of variables passed to processors
return string
    protected function applyLayout($content, $vars)
    {
        $layoutName = $this->getParam('page.layout', ViewFactory::DEFAULT_LAYOUT_SCRIPT);
        $inputFile = $this->getInputFile();
        $inputFile = str_replace('\\', '/', $inputFile);
        $pos = strpos($inputFile, '/entries');
        // make sure that input path is normalized to root entries directory
        if (false !== $pos) {
            $inputFile = substr($inputFile, 0, $pos + 8) . '/entry';
        }
        $layoutPath = realpath(dirname($inputFile) . '/../layouts/' . $layoutName);
        $factory = new ViewFactory($layoutPath);
        $layout = $factory->create();
        // essentially layout is Site\View as well
        $layout->hasLayout(false);
        // no nested layouts
        $vars['content'] = $content;
        $vars['entry'] = $vars['page'];
        return $layout->render($vars);
    }