Skip to content

Commit ce36610

Browse files
committed
Fix updating context inside custom helpers
Resolves zordius/lightncandy#350
1 parent da0da0f commit ce36610

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

src/Compiler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public function composePHPRender(string $code): string
9191
partials: isset(\$options['partials']) ? array_merge(\$partials, \$options['partials']) : \$partials,
9292
data: isset(\$options['data']) ? array_merge(['root' => \$in], \$options['data']) : ['root' => \$in],
9393
);
94+
\$in = &\$cx->data['root'];
9495
return '$code';
9596
};
9697
VAREND;

tests/RegressionTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,6 +1545,24 @@ public static function issueProvider(): array
15451545
'expected' => ' {{bar}} content',
15461546
],
15471547

1548+
[
1549+
'id' => 350,
1550+
'template' => <<<_hbs
1551+
Before: {{var}}
1552+
(Setting Variable) {{setvar "var" "Foo"}}
1553+
After: {{var}}
1554+
_hbs,
1555+
'data' => ['var' => 'value'],
1556+
'options' => new Options(
1557+
helpers: [
1558+
'setvar' => function ($name, $value, HelperOptions $options) {
1559+
$options->data['root'][$name] = $value;
1560+
},
1561+
],
1562+
),
1563+
'expected' => "Before: value\n(Setting Variable) \nAfter: Foo",
1564+
],
1565+
15481566
[
15491567
'id' => 357,
15501568
'template' => '{{echo (echo "foobar(moo).")}}',

0 commit comments

Comments
 (0)