![]() |
pass variable from 1 template to the other
I'm trying to pass a variable value from Fast_Lane_Checkout/cart_substotal.tpl. to main/cart.tpl.
I've created a variable call $newsubtotal in the template {include file="modules/Fast_Lane_Checkout/cart_substotal.tpl" newsubtotal2=$newsubtotal1} like this: {math equation="subtotal+ship" subtotal=$cart.display_discounted_subtotal ship=$upsship assign=newsubtotal}{include file="currency.tpl" value=$newsubtotal} I want to pass the $newsubtotal value to the main/cart.tpl. I tried using the include command: {include file="modules/Fast_Lane_Checkout/cart_substotal.tpl" newsubtotal1=$newsubtotal} , but the newsubtotal1 is blank. Can someone help with this? Thanks! |
Re: pass variable from 1 template to the other
As a last resort you can use PHP "global". declare the variable as global in both functions then you can see and modify it in both.
|
Re: pass variable from 1 template to the other
Thanks. - Can you show me an example?
|
Re: pass variable from 1 template to the other
In cart_subtotal.tpl you get the smarty var value $newsubtotal and put it in a global php var $phpnewsubtotal.
Code:
{php} Then in cart.tpl you get the value from the php global var and put it in the smarty var. Code:
{php} That's it I think. Be warned there is probably a more conventional way to do this as you will no doubt find out in subsequent replys by other folks. |
Re: pass variable from 1 template to the other
It doesn't seem to like the php code for the cart_subtotal.tpl - it just echo's out:
global $phpnewsubtotal; $phpnewsubtotal = $smarty->get_template_vars('newsubtotal'); I put the php code in cart.tpl at the top of the page and that seemed to be ok, but no matter where I put the php code for cart_subtotal.pl it won't execute. |
Re: pass variable from 1 template to the other
cart_subtotal is a tpl file right? not a php file?
Should work fine. Maybe someone else could help. |
Re: pass variable from 1 template to the other
Quote:
$smarty->get_template_vars('newsubtotal'); with $this->get_template_vars('newsubtotal'); |
Re: pass variable from 1 template to the other
Also should be
{/php} |
Re: pass variable from 1 template to the other
Thanks! I can't believe I missed that backslash. I'll give that a go.
I did come up with another way in the meanwhile. It's kind of hack... from a response to the question I posed in the smarty forum: After I assigned $newsubtotal in the cart_subtotal, I captured the value: {capture name="mytotal"}{$newsubtotal}{/capture} then in cart.tpl I used: {include file="currency.tpl" value=$smarty.capture.mytotal} |
All times are GMT -8. The time now is 06:31 PM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.