mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 02:16:41 +00:00
added a proper error message when block() is called without arguments
This commit is contained in:
@@ -344,7 +344,12 @@ class Twig_ExpressionParser
|
||||
|
||||
return new Twig_Node_Expression_Parent($this->parser->peekBlockStack(), $line);
|
||||
case 'block':
|
||||
return new Twig_Node_Expression_BlockReference($this->parseArguments()->getNode(0), false, $line);
|
||||
$args = $this->parseArguments();
|
||||
if (count($args) < 1) {
|
||||
throw new Twig_Error_Syntax('The "block" function takes one argument (the block name).', $line, $this->parser->getStream()->getSourceContext()->getName());
|
||||
}
|
||||
|
||||
return new Twig_Node_Expression_BlockReference($args->getNode(0), false, $line);
|
||||
case 'attribute':
|
||||
$args = $this->parseArguments();
|
||||
if (count($args) < 2) {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
--TEST--
|
||||
"block" function without arguments
|
||||
--TEMPLATE--
|
||||
{% extends 'base.twig' %}
|
||||
{% block bar %}BAR{% endblock %}
|
||||
--TEMPLATE(base.twig)--
|
||||
{% block foo %}{{ block() }}{% endblock %}
|
||||
{% block bar %}BAR_BASE{% endblock %}
|
||||
--DATA--
|
||||
return array()
|
||||
--EXCEPTION--
|
||||
Twig_Error_Syntax: The "block" function takes one argument (the block name) in "base.twig" at line 2.
|
||||
Reference in New Issue
Block a user