AppleEater Posted October 8, 2013 Share Posted October 8, 2013 (edited) 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: {$id_cms=""} . . . {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" /> </a> 2. in the included file: {if {$id_attribute_group|intval}==4} {$id_cms=6} {else} {$id_cms=50} {/if} Why isn't the $id_cms variable inside the included file update the external variable? Edited October 8, 2013 by AppleEater (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted October 8, 2013 Share Posted October 8, 2013 if you use simple {$id_cms} somewhere it displays value defined in if condition? Link to comment Share on other sites More sharing options...
AppleEater Posted October 8, 2013 Author Share Posted October 8, 2013 if you use simple {$id_cms} somewhere it displays value defined in if condition? only inside the included tpl. in the calling tpl it displays the originaly assgined value. . 1 Link to comment Share on other sites More sharing options...
AppleEater Posted October 8, 2013 Author Share Posted October 8, 2013 (edited) 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 October 8, 2013 by AppleEater (see edit history) 3 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now