bug #1288 added an error message when trying to import an undefined block from a trait (fabpot)

This PR was merged into the master branch.

Discussion
----------

added an error message when trying to import an undefined block from a trait

Commits
-------

a2c6db7 added an error message when trying to import an undefined block from a trait
This commit is contained in:
Fabien Potencier
2013-12-06 16:28:39 +01:00
3 changed files with 22 additions and 1 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
* 1.15.1 (2013-XX-XX)
* n/a
* added an error message when trying to import an undefined block from a trait
* 1.15.0 (2013-12-06)
+12
View File
@@ -170,6 +170,18 @@ class Twig_Node_Module extends Twig_Node
foreach ($trait->getNode('targets') as $key => $value) {
$compiler
->write(sprintf("if (!isset(\$_trait_%s_blocks[", $i))
->string($key)
->raw("])) {\n")
->indent()
->write("throw new Twig_Error_Runtime(sprintf('Block ")
->string($key)
->raw(" is not defined in trait ")
->subcompile($trait->getNode('template'))
->raw(".'));\n")
->outdent()
->write("}\n\n")
->write(sprintf("\$_trait_%s_blocks[", $i))
->subcompile($value)
->raw(sprintf("] = \$_trait_%s_blocks[", $i))
@@ -0,0 +1,9 @@
--TEST--
Exception for an undefined trait
--TEMPLATE--
{% use 'foo' with foobar as bar %}
--TEMPLATE(foo)--
{% block bar %}
{% endblock %}
--EXCEPTION--
Twig_Error_Runtime: Block "foobar" is not defined in trait "foo" in "index.twig".