Skip to content

Unset or null parameters are overwritten while including block #198

@prosky

Description

@prosky

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); ?>'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions