Jump to content

[Solved] smarty variables inheritence and scope in tpl


Recommended Posts

I'm trying to update a variable inside an include file, but it seems the variable only lives inside the incuded tpl. using PS1.5.5


here's what I've done:

1. in product.tpl:

{include file="$tpl_dir./assign_cms_page.tpl" id_cms=$id_cms}

<a href="{$link->getCMSLink($id_cms)|escape:'html'}?content_only=1" class="iframe">
<img src="{$img_dir}bg/help.jpg" alt="help" />

2. in the included file:

{if {$id_attribute_group|intval}==4}

Why isn't the $id_cms variable inside the included file update the external variable?


Edited by AppleEater (see edit history)
Link to comment
Share on other sites

ok, you learn something new every day....


according to the smarty tutorial :


  • You can use all variables from the including template inside the included template. But changes to variables or new created variables inside the included template have local scope and are not visible inside the including template after the {include} statement. This default behaviour can be changed for all variables assigned in the included template by using the scope attribute at the{include} statement or for individual variables by using the scope attribute at the {assign} statement. The later is useful to return values from the included template to the including template.


So I resolved the problem by modifying the calling line like this (got some help from stackoverflow ):

{include file="$tpl_dir./assign_cms_page.tpl" scope="parent"}
Edited by AppleEater (see edit history)
  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...