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

Parent scope in template blocks does not bubble up when it extends another template #850

Open
maryo opened this issue Jan 21, 2023 · 0 comments · May be fixed by #851
Open

Parent scope in template blocks does not bubble up when it extends another template #850

maryo opened this issue Jan 21, 2023 · 0 comments · May be fixed by #851

Comments

@maryo
Copy link

maryo commented Jan 21, 2023

I'd like to update Smarty in a big legacy project with code like this. It is just a simplfied example which stopped working in v3.1.28.
More precisely the last commit where this was working is 54d54e5.
So these are the changes affecting this behavior
54d54e5...2ba7109

See PR #851

index.tpl:

{$test="index"}
{include "./include.tpl"}
test: {$test}

Displays "index". I'd like to propagate "include_base" (see include_base.tpl) without polluting the global/root scope.

include.tpl:

{extends "./include_base.tpl"}
{*$test=$test scope=parent*} {* this also doesn't help because the variable in `include_base.tpl` is assigned later that this code *}

include_base.tpl:

{$test="include_base" scope=parent}

Trying to affect the execution order using blocks

include.tpl:

{extends "./include_base.tpl"}

{block content append}
    {$test=$test scope=parent} {* this also doesn't help because the parent of this template is not "index.tpl" *}
    {*$smarty.template_object->parent->parent->_assignInScope("test", $test)*} {* this is the only hack i came up with that works *}
{/block}

include_base.tpl:

{block content}
    {$test="include_base" scope=parent}
{/block}

Is it a bug or an intended behavior? Shouldn't there be a way how to propagate variable to the parent "scope by scope"?.
Our code is legacy and propagation up the tree might even not be a good idea but it is still a BC break that prevents us to update Smarty without fear.

BTW Thanks for everyone who still tries to maintain this library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant