Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Return variables from included template

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
svowl
Smarty n00b


Joined: 26 Sep 2003
Posts: 4

PostPosted: Fri Sep 26, 2003 7:37 am    Post subject: Return variables from included template Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP