Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BlockMacros - define: fixed variables extracting #131

Merged
merged 1 commit into from Aug 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Latte/Macros/BlockMacros.php
Expand Up @@ -9,7 +9,6 @@

use Latte;
use Latte\CompileException;
use Latte\Engine;
use Latte\Helpers;
use Latte\MacroNode;
use Latte\PhpWriter;
Expand Down Expand Up @@ -341,7 +340,8 @@ public function macroBlockEnd(MacroNode $node, PhpWriter $writer)
}
if (empty($node->data->leave)) {
if (preg_match('#\$|n:#', $node->content)) {
$node->content = '<?php ' . (isset($node->data->args) ? $node->data->args : 'extract($_args);') . ' ?>' . $node->content;
$node->content = '<?php ' . (isset($node->data->args) ? 'extract($this->params); ' . $node->data->args : 'extract($_args);') . ' ?>'
. $node->content;
}
$this->namedBlocks[$node->data->name] = $tmp = preg_replace('#^\n+|(?<=\n)[ \t]+\z#', '', $node->content);
$node->content = substr_replace($node->content, $node->openingCode . "\n", strspn($node->content, "\n"), strlen($tmp));
Expand Down
4 changes: 2 additions & 2 deletions tests/Latte/BlockMacros.defineblock.phpt
Expand Up @@ -24,7 +24,7 @@ $template = <<<'EOD'
{include #test, var => 20}

{define testargs $var1, $var2}
Variables {$var1}, {$var2}
Variables {$var1}, {$var2}, {$hello}
{/define}

{include testargs, 1}
Expand All @@ -37,5 +37,5 @@ Assert::matchFile(
);
Assert::matchFile(
__DIR__ . '/expected/BlockMacros.defineblock.html',
$latte->renderToString($template)
$latte->renderToString($template, ['hello' => 'world'])
);
2 changes: 1 addition & 1 deletion tests/Latte/expected/BlockMacros.defineblock.html
Expand Up @@ -4,4 +4,4 @@
This is definition #20


Variables 1,
Variables 1, , world
4 changes: 3 additions & 1 deletion tests/Latte/expected/BlockMacros.defineblock.phtml
Expand Up @@ -49,8 +49,10 @@ class Template%a% extends Latte\Runtime\Template

function blockTestargs($_args)
{
extract($this->params);
list($var1, $var2) = $_args + [NULL, NULL, ];
?> Variables <?php echo LR\Filters::escapeHtmlText($var1) /* line 11 */ ?>, <?php echo LR\Filters::escapeHtmlText($var2) /* line 11 */ ?>
?> Variables <?php echo LR\Filters::escapeHtmlText($var1) /* line 11 */ ?>, <?php echo LR\Filters::escapeHtmlText($var2) /* line 11 */ ?>, <?php
echo LR\Filters::escapeHtmlText($hello) /* line 11 */ ?>

<?php
}
Expand Down