lib/Pico.php
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;
    }
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;
    }
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 ; }
Returns the Twig template engine

This method triggers the `onTwigRegistered` event when the Twig template
engine wasn't initiated yet. When initiating Twig, this method also
registers Pico's core Twig filter `content` as well as Pico's
{@see PicoTwigExtension} Twig extension.

@see Pico::getTwig()
@see http://twig.sensiolabs.org/ Twig website
@see https://github.com/twigphp/Twig Twig on GitHub

@return Twig_Environment|null Twig template engine
Returns the Twig template engine