mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-24 23:16:26 +00:00
Fix the possibility to override an aliased block (via use)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# 3.15.0 (2024-XX-XX)
|
||||
|
||||
* Fix the possibility to override an aliased block (via use)
|
||||
* Add template cache hot reload
|
||||
* Allow Twig callable argument names to be free-form (snake-case or camelCase) independently of the PHP callable signature
|
||||
They were automatically converted to snake-cased before
|
||||
|
||||
@@ -244,7 +244,11 @@ final class ModuleNode extends Node
|
||||
->string($key)
|
||||
->raw(\sprintf(']; unset($_trait_%s_blocks[', $i))
|
||||
->string($key)
|
||||
->raw("]);\n\n")
|
||||
->raw("]); \$this->traitAliases[")
|
||||
->subcompile($value)
|
||||
->raw("] = ")
|
||||
->string($key)
|
||||
->raw(";\n\n")
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -37,6 +37,7 @@ abstract class Template
|
||||
protected $parents = [];
|
||||
protected $blocks = [];
|
||||
protected $traits = [];
|
||||
protected $traitAliases = [];
|
||||
protected $extensions = [];
|
||||
protected $sandbox;
|
||||
|
||||
@@ -477,7 +478,7 @@ abstract class Template
|
||||
public function yieldParentBlock($name, array $context, array $blocks = []): iterable
|
||||
{
|
||||
if (isset($this->traits[$name])) {
|
||||
yield from $this->traits[$name][0]->yieldBlock($name, $context, $blocks, false);
|
||||
yield from $this->traits[$name][0]->yieldBlock($this->traitAliases[$name] ?? $name, $context, $blocks, false);
|
||||
} elseif ($parent = $this->getParent($context)) {
|
||||
yield from $parent->unwrap()->yieldBlock($name, $context, $blocks, false);
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
--TEST--
|
||||
"use" tag with an overridden block that is aliased
|
||||
--TEMPLATE--
|
||||
{% use "blocks.twig" with bar as baz %}
|
||||
|
||||
{% block foo %}{{ parent() }}+{% endblock %}
|
||||
|
||||
{% block baz %}{{ parent() }}+{% endblock %}
|
||||
|
||||
{{ block('foo') }}
|
||||
{{ block('baz') }}
|
||||
--TEMPLATE(blocks.twig)--
|
||||
{% block foo %}Foo{% endblock %}
|
||||
{% block bar %}Bar{% endblock %}
|
||||
--DATA--
|
||||
return []
|
||||
--EXPECT--
|
||||
Foo+
|
||||
Bar+
|
||||
Foo+
|
||||
Bar+
|
||||
Reference in New Issue
Block a user