|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
svowl Smarty n00b
Joined: 26 Sep 2003 Posts: 4
|
Posted: Fri Sep 26, 2003 7:37 am Post subject: Return variables from included template |
|
|
Hi,
I have the following problem with Smarty: I need to calculate and display the summary value of prices in two different arrays. But {section} for second array is located in a separate template because it is related to a module. There is a light version of my code below:
Code: | template1.tpl:
{assign var="sum" value=0}
First list<br>
{section name="p" loop=$products}
{math equation="x+y" x=$sum y=$products[p].price assign="sum"}
Price: ${$products[p].price}<br>
{/section}
{if $modules.gc ne ""}
<br>
{include file="modules/gc/gc_calc.tpl"}
{/if}
<hr>
Sum: ${$sum}
template2:
Second list<br>
{section name="g" loop=$gc}
{math equation="x+y" x=$sum y=$gc[g].price assign="sum"}
Price: ${$gc[g].price}<br>
{/section}
|
After this code is run we get:
Code: | Output:
First list
Price: $10
Price: $10
Price: $10
Second list
Price: $10
Price: $10
Sum: $30 |
The correct value for Sum must be $50.
I think it will be very helpful to create something like a {return} tag to return variables back to the main template:
{return var="sum"}
...
{return var="var2"}
{return var="var3}
...
Thank you |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|