mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 12:06:56 +00:00
tweaked the error message when using extends in a block/macro
This commit is contained in:
+1
-1
@@ -251,7 +251,7 @@ class Parser implements \Twig_ParserInterface
|
||||
|
||||
public function peekBlockStack()
|
||||
{
|
||||
return $this->blockStack[\count($this->blockStack) - 1];
|
||||
return isset($this->blockStack[\count($this->blockStack) - 1]) ? $this->blockStack[\count($this->blockStack) - 1] : null;
|
||||
}
|
||||
|
||||
public function popBlockStack()
|
||||
|
||||
@@ -29,8 +29,10 @@ class ExtendsTokenParser extends AbstractTokenParser
|
||||
{
|
||||
$stream = $this->parser->getStream();
|
||||
|
||||
if (!$this->parser->isMainScope()) {
|
||||
throw new SyntaxError('Cannot extend from a block.', $token->getLine(), $stream->getSourceContext());
|
||||
if ($this->parser->peekBlockStack()) {
|
||||
throw new SyntaxError('Cannot use "extend" in a block.', $token->getLine(), $stream->getSourceContext());
|
||||
} elseif (!$this->parser->isMainScope()) {
|
||||
throw new SyntaxError('Cannot use "extend" in a macro.', $token->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
|
||||
if (null !== $this->parser->getParent()) {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
--TEST--
|
||||
"extends" tag in a block
|
||||
--TEMPLATE--
|
||||
{% block foo %}
|
||||
{% extends "foo.twig" %}
|
||||
{% endblock %}
|
||||
--DATA--
|
||||
return []
|
||||
--EXCEPTION--
|
||||
Twig\Error\SyntaxError: Cannot use "extend" in a block in "index.twig" at line 3.
|
||||
@@ -0,0 +1,10 @@
|
||||
--TEST--
|
||||
"extends" tag in a macro
|
||||
--TEMPLATE--
|
||||
{% macro foo() %}
|
||||
{% extends "foo.twig" %}
|
||||
{% endmacro %}
|
||||
--DATA--
|
||||
return []
|
||||
--EXCEPTION--
|
||||
Twig\Error\SyntaxError: Cannot use "extend" in a macro in "index.twig" at line 3.
|
||||
@@ -1,8 +0,0 @@
|
||||
--TEST--
|
||||
"extends" tag
|
||||
--TEMPLATE--
|
||||
{% block content %}
|
||||
{% extends "foo.twig" %}
|
||||
{% endblock %}
|
||||
--EXCEPTION--
|
||||
Twig\Error\SyntaxError: Cannot extend from a block in "index.twig" at line 3.
|
||||
Reference in New Issue
Block a user