/** * {@inheritdoc} * * @param \Phalcon\Mvc\ViewInterface $view * @param \Phalcon\DiInterface $di * @param array $options */ public function __construct($view, $di = null, $options = array(), $arrFolder = array()) { $arrFolder[] = $view->getViewsDir(); $loader = new \Twig_Loader_Filesystem($arrFolder); if (!is_array($options)) { $options = array(); } $this->twig = new Twig\Environment($di, $loader, $options); $this->twig->addExtension(new Twig\CoreExtension()); $this->registryFunctions($view, $di); // $function = new Twig_SimpleFunction('inc', function(Twig_Environment $env, $context, $template, $variables = array(), $withContext = true, $ignoreMissing = false, $sandboxed = false) { // // GET json filename // $jsonFilename = str_replace('.twig', '.json', $template); // // IF json default data exists // if(file_exists(ABS_ROOT.'views/'.$jsonFilename)) // { // // GET data // $arrData = json_decode(file_get_contents(ABS_ROOT.'views/'.$jsonFilename), true); // // MERGE data into context // foreach($arrData AS $key => $data) // { // if(!array_key_exists($key, $context)) // { // $context[$key] = $data; // } // } // } // // INCLUDE and display template // echo twig_include($env, $context, $template, $variables, $withContext, $ignoreMissing, $sandboxed); // }, array('needs_environment' => true, 'needs_context' => true)); // $this->twig->addFunction($function); parent::__construct($view, $di); }
/** * {@inheritdoc} * * @param ViewBaseInterface $view * @param DiInterface $di * @param array $options * @param array $userFunctions */ public function __construct(ViewBaseInterface $view, DiInterface $di = null, $options = array(), $userFunctions = array()) { $loader = new \Twig_Loader_Filesystem($view->getViewsDir()); $this->twig = new Twig\Environment($di, $loader, $options); $this->twig->addExtension(new Twig\CoreExtension()); $this->registryFunctions($view, $di, $userFunctions); parent::__construct($view, $di); }
/** * {@inheritdoc} * * @param \Phalcon\Mvc\ViewInterface $view * @param \Phalcon\DiInterface $di * @param array $options * @param array $userFunctions */ public function __construct($view, \Phalcon\DiInterface $di = null, $options = [], $userFunctions = []) { $loader = new \Twig_Loader_Filesystem($view->getViewsDir()); $this->twig = new Environment($di, $loader, $options); $this->twig->addExtension(new CoreExtension()); $this->twig->addExtension(new \Twig_Extension_Debug()); $this->registryFunctions($view, $di, $userFunctions); parent::__construct($view, $di); }