Skip to content

Commit

Permalink
Runtime: Adds support for multiple interpolations in tag method names (
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnathonKoster committed Apr 11, 2022
1 parent f4cdf20 commit 067fcaf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/View/Antlers/Language/Runtime/NodeProcessor.php
Expand Up @@ -1279,14 +1279,15 @@ public function reduce($processNodes)
$tagName = $node->name->getCompoundTagName();
$tagMethod = $node->name->getMethodName();

if (array_key_exists($tagMethod, $node->processedInterpolationRegions)) {
if (! empty($node->processedInterpolationRegions)) {
foreach ($node->processedInterpolationRegions as $region => $regionNodes) {
$this->canHandleInterpolations[$region] = $regionNodes;
if (! empty($node->processedInterpolationRegions)) {
foreach ($node->processedInterpolationRegions as $region => $regionNodes) {
$this->canHandleInterpolations[$region] = $regionNodes;

if (Str::contains($tagMethod, $region)) {
$tagMethod = str_replace($region, $this->evaluateDeferredInterpolation($region), $tagMethod);
}
}

$tagMethod = $this->evaluateDeferredInterpolation($tagMethod);
$tagName = $node->name->name.':'.$tagMethod;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/Antlers/Runtime/ParametersTest.php
Expand Up @@ -127,6 +127,14 @@ public function test_interpolations_can_be_used_as_part_of_a_tag_method()
$this->assertSame('hello_world', $this->renderString($template, [
'var_name' => 'hello_world',
], true));

$template = <<<'EOT'
{{ echo_method:components/{var_name}/{{ var_name}}/{2+5+10}/more/{var_name|upper} }}
EOT;

$this->assertSame('components/button/button/17/more/BUTTON', $this->renderString($template, [
'var_name' => 'button',
], true));
}

public function test_array_syntax_modifiers_work_on_multi_part_variable_paths()
Expand Down

0 comments on commit 067fcaf

Please sign in to comment.