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);
    }