Twig_Environment::addNodeVisitor PHP Method

addNodeVisitor() public method

Registers a Node Visitor.
public addNodeVisitor ( Twig_NodeVisitorInterface $visitor )
$visitor Twig_NodeVisitorInterface A Twig_NodeVisitorInterface instance
    public function addNodeVisitor(Twig_NodeVisitorInterface $visitor)
    {
        if (null === $this->visitors) {
            $this->getNodeVisitors();
        }

        $this->visitors[] = $visitor;
    }

Usage Example

 /**
  * @dataProvider getAttributeExceptions
  */
 public function testGetAttributeExceptions($template, $message, $useExt)
 {
     $name = 'index_' . ($useExt ? 1 : 0);
     $templates = array($name => $template . $useExt);
     $env = new Twig_Environment(new Twig_Loader_Array($templates), array('strict_variables' => true));
     if (!$useExt) {
         $env->addNodeVisitor(new CExtDisablingNodeVisitor());
     }
     $template = $env->loadTemplate($name);
     $context = array('string' => 'foo', 'array' => array('foo' => 'foo'), 'array_access' => new Twig_TemplateArrayAccessObject());
     try {
         $template->render($context);
     } catch (Twig_Error_Runtime $e) {
         $this->assertEquals(sprintf($message, $name), $e->getMessage());
     }
 }
All Usage Examples Of Twig_Environment::addNodeVisitor