mirror of
https://github.com/twigphp/Twig.git
synced 2026-10-20 18:55:56 +00:00
Merge branch '1.x' into 2.x
* 1.x: fixed "include" with "ignore missing" when an error loading occurs in the included template (again) fixed "include" with "ignore missing" when an error loading occurs in the included template
This commit is contained in:
+29
-18
@@ -37,43 +37,54 @@ class IncludeNode extends Node implements NodeOutputInterface
|
||||
$compiler->addDebugInfo($this);
|
||||
|
||||
if ($this->getAttribute('ignore_missing')) {
|
||||
$template = $compiler->getVarName();
|
||||
|
||||
$compiler
|
||||
->write(sprintf("$%s = null;\n", $template))
|
||||
->write("try {\n")
|
||||
->indent()
|
||||
->write(sprintf('$%s = ', $template))
|
||||
;
|
||||
}
|
||||
|
||||
$this->addGetTemplate($compiler);
|
||||
$this->addGetTemplate($compiler);
|
||||
|
||||
$compiler->raw('->display(');
|
||||
|
||||
$this->addTemplateArguments($compiler);
|
||||
|
||||
$compiler->raw(");\n");
|
||||
|
||||
if ($this->getAttribute('ignore_missing')) {
|
||||
$compiler
|
||||
->raw(";\n")
|
||||
->outdent()
|
||||
->write("} catch (LoaderError \$e) {\n")
|
||||
->indent()
|
||||
->write("// ignore missing template\n")
|
||||
->outdent()
|
||||
->write("}\n\n")
|
||||
->write("}\n")
|
||||
->write(sprintf("if ($%s) {\n", $template))
|
||||
->indent()
|
||||
->write(sprintf('$%s->display(', $template))
|
||||
;
|
||||
$this->addTemplateArguments($compiler);
|
||||
$compiler
|
||||
->raw(");\n")
|
||||
->outdent()
|
||||
->write("}\n")
|
||||
;
|
||||
} else {
|
||||
$this->addGetTemplate($compiler);
|
||||
$compiler->raw('->display(');
|
||||
$this->addTemplateArguments($compiler);
|
||||
$compiler->raw(");\n");
|
||||
}
|
||||
}
|
||||
|
||||
protected function addGetTemplate(Compiler $compiler)
|
||||
{
|
||||
$compiler
|
||||
->write('$this->loadTemplate(')
|
||||
->subcompile($this->getNode('expr'))
|
||||
->raw(', ')
|
||||
->repr($this->getTemplateName())
|
||||
->raw(', ')
|
||||
->repr($this->getTemplateLine())
|
||||
->raw(')')
|
||||
;
|
||||
->write('$this->loadTemplate(')
|
||||
->subcompile($this->getNode('expr'))
|
||||
->raw(', ')
|
||||
->repr($this->getTemplateName())
|
||||
->raw(', ')
|
||||
->repr($this->getTemplateLine())
|
||||
->raw(')')
|
||||
;
|
||||
}
|
||||
|
||||
protected function addTemplateArguments(Compiler $compiler)
|
||||
|
||||
Reference in New Issue
Block a user