X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   pass variable from 1 template to the other (https://forum.x-cart.com/showthread.php?t=46603)

rshandel 03-28-2009 10:09 AM

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!

rogue 03-29-2009 05:25 AM

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.

rshandel 03-29-2009 05:37 AM

Re: pass variable from 1 template to the other
 
Thanks. - Can you show me an example?

rogue 03-29-2009 06:21 AM

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}
  global $phpnewsubtotal;
  $phpnewsubtotal = $smarty->get_template_vars('newsubtotal');
{\php}


Then in cart.tpl you get the value from the php global var and put it in the smarty var.

Code:

{php}
  global $phpnewsubtotal;
  $this->assign("newsubtotal", $phpnewsubtotal);
{\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.

rshandel 03-29-2009 07:26 AM

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.

rogue 03-29-2009 10:15 AM

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.

mikalou 06-04-2009 01:05 PM

Re: pass variable from 1 template to the other
 
Quote:

It doesn't seem to like the php code for the cart_subtotal.tpl - it just echo's out:

Try replacing
$smarty->get_template_vars('newsubtotal');
with
$this->get_template_vars('newsubtotal');

mikalou 06-04-2009 01:23 PM

Re: pass variable from 1 template to the other
 
Also should be
{/php}

rshandel 06-04-2009 01:59 PM

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.