Skip to content

Variables visibility between blocks depend on block order #178

@milo

Description

@milo

Version: master (f7b0fa8)

Following code emits notice: PHP Notice: Undefined variable: x

<?php
# composer require latte/latte dev-master
require __DIR__ . '/vendor/autoload.php';

$latte = '
{define a}
	{var x => "X"}
	{include #b}
{/}

{define b}
	{$x}
{/}

{include a}
';

$engine = new Latte\Engine;
$engine->setLoader(new Latte\Loaders\StringLoader);
echo $engine->compile($latte);
$engine->render($latte);

To make it work, I have to pass $x explicitly to block. Or, If I change blocks order, it works:

$latte = '
{define b}
	{$x}
{/}

{define a}
	{var x => "X"}
	{include #b}
{/}

{include a}
';

The only difference between compiled template is in method blockA():

# Non working
function blockA($_args)
{
        extract($_args);
        $x = "X";
        $this->renderBlock('b', $this->params, 'html');
}

# Working
function blockA($_args)
{
        extract($_args);
        $x = "X";
        $this->renderBlock('b', get_defined_vars(), 'html');
}

I'm not sure it is bug or by desing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions