public function getTwig()
    {
        if ($this->twig === null) {
            $twigConfig = $this->getConfig('twig_config');

            $twigLoader = new Twig_Loader_Filesystem($this->getThemesDir() . $this->getConfig('theme'));
            $this->twig = new Twig_Environment($twigLoader, $twigConfig);
            $this->twig->addExtension(new PicoTwigExtension($this));

            if (!empty($twigConfig['debug'])) {
                $this->twig->addExtension(new Twig_Extension_Debug());
            }

            // register content filter
            // we pass the $pages array by reference to prevent multiple parser runs for the same page
            // this is the reason why we can't register this filter as part of PicoTwigExtension
            $pico = $this;
            $pages = &$this->pages;
            $this->twig->addFilter(new Twig_SimpleFilter('content', function ($page) use ($pico, &$pages) {
                if (isset($pages[$page])) {
                    $pageData = &$pages[$page];
                    if (!isset($pageData['content'])) {
                        $pageData['content'] = $pico->prepareFileContent($pageData['raw_content'], $pageData['meta']);
                        $pageData['content'] = $pico->parseFileContent($pageData['content']);
                    }
                    return $pageData['content'];
                }
                return null;
            }));

            // trigger onTwigRegistration event
            $this->triggerEvent('onTwigRegistered', array(&$this->twig));
        }

        return $this->twig;
    }