Beispiel #1
0
 public function compile(JsCompiler $compiler, \Twig_NodeInterface $node)
 {
     if (!$node instanceof \Twig_Node_If) {
         throw new \RuntimeException(sprintf('$node must be an instanceof of \\If, but got "%s".', get_class($node)));
     }
     $compiler->addDebugInfo($node);
     for ($i = 0; $i < count($node->getNode('tests')); $i += 2) {
         if ($i > 0) {
             $compiler->outdent()->write("} else if (");
         } else {
             $compiler->write('if (');
         }
         $compiler->subcompile($node->getNode('tests')->getNode($i))->raw(") {\n")->indent()->subcompile($node->getNode('tests')->getNode($i + 1));
     }
     if ($node->hasNode('else') && null !== $node->getNode('else')) {
         $compiler->outdent()->write("} else {\n")->indent()->subcompile($node->getNode('else'));
     }
     $compiler->outdent()->write("}\n");
 }
Beispiel #2
0
 protected function compileDisplayFooter(JsCompiler $compiler, \Twig_NodeInterface $node)
 {
     $compiler->outdent()->write("};\n\n");
 }