I have a "links.tpl" file which contains lines with many variables such as below
{assign var=link_main value="index.php"}
{assign var=link_login value="?a=login"}
but when i include this file in home.tpl using {include file="file.tpl"}
the variables {$link_main}, {$link_login}
are not included
i put the {assign var=link_main value="index.php"}
in home.tpl and it works but not from included file
i have tried adding scope=global
to variable and parent to include but nothing happened
I tried the last few hours finding a solution, any help is appreciated
What you're doing should work. Testing on my Mac:
File test/testInclude.tpl
{assign var='assignedVar' value='foo' scope='global'}
assignedVar in child is {$assignedVar}
<br/>
File test/test.tpl
{include file='test/testInclude.tpl'}
{if isset($assignedVar)}
assignedVar is set in parent {$assignedVar}
{else}
assignedVar is not set in parent
{/if}
<br/>
Outputs
assignedVar in child is foo
assignedVar is set in parent foo
That really should work - if not then there's something really weird going on with your instance of Smarty. Could it be that the template is being cached and not being regenerated when the variables are changed?
Obviously you should figure out what's going wrong, but if all else fails you could also use the alternative capture function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With