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

Unset or null parameters are overwritten while including block #198

Closed
prosky opened this issue Sep 18, 2019 · 1 comment
Closed

Unset or null parameters are overwritten while including block #198

prosky opened this issue Sep 18, 2019 · 1 comment

Comments

@prosky
Copy link

@prosky prosky commented Sep 18, 2019

Version: Nette 3.0 Latte v2.5.x-dev

Bug Description

While including block, unset or null parameters are overwriten by existing variables.

Steps To Reproduce

{define someblock $include ,$text}
	<span>{$text}</span>
	{if $include}{include someblock false,null}{/if}
	{if $include}{include someblock false}{/if}
{/define}
{spaceless}{include someblock true,'text'}{/spaceless}

Result is

<span>text</span><span>text</span><span>text</span>

Expected Behavior

But it should be

<span>text</span><span></span><span></span>

Or at worst

<span>text</span><span></span><span>text</span>

Possible Solution

Now the generated code looks like:

extract($_args, EXTR_SKIP);
$include = $_args[0] ?? $include ?? null;
$text = $_args[1] ?? $text ?? null;

Meybe better would be:

$include = $_args[0] ?? null;
$text = $_args[1] ?? null;
extract($_args, EXTR_SKIP);

So the block arguments has always bigger priority

So the solution is in src/Latte/Macros/BlockMacros.php
change

 '<?php extract($_args, EXTR_SKIP);' . ($node->data->args ?? '') . ' ?>'

to

'<?php ' . ($node->data->args ?? '') . ' extract($_args, EXTR_SKIP); ?>'
@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Sep 18, 2019

It seems that #184 need more complex solution…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.