Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

pass variable from 1 template to the other

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 03-28-2009, 10:09 AM
 
rshandel rshandel is offline
 

Senior Member
  
Join Date: Feb 2009
Posts: 125
 

Default 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!
__________________
x-cart 4.1.12
x-cart 4.2
Reply With Quote
  #2  
Old 03-29-2009, 05:25 AM
  rogue's Avatar 
rogue rogue is offline
 

X-Adept
  
Join Date: Apr 2007
Location: Loveland, Ohio
Posts: 770
 

Default 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.
__________________
Richard Williams
Rogue Wave Limited

Initial Inventory Imports
Daily Inventory Updates
Daily Inventory Reports
Drop Ship Support
Order Export to Shipper/Supplier
Shopping Feeds That Work
Programming for X-Cart

richard@roguewavelimited.com
http://www.roguewavelimited.com
Reply With Quote
  #3  
Old 03-29-2009, 05:37 AM
 
rshandel rshandel is offline
 

Senior Member
  
Join Date: Feb 2009
Posts: 125
 

Default Re: pass variable from 1 template to the other

Thanks. - Can you show me an example?
__________________
x-cart 4.1.12
x-cart 4.2
Reply With Quote
  #4  
Old 03-29-2009, 06:21 AM
  rogue's Avatar 
rogue rogue is offline
 

X-Adept
  
Join Date: Apr 2007
Location: Loveland, Ohio
Posts: 770
 

Default 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.
__________________
Richard Williams
Rogue Wave Limited

Initial Inventory Imports
Daily Inventory Updates
Daily Inventory Reports
Drop Ship Support
Order Export to Shipper/Supplier
Shopping Feeds That Work
Programming for X-Cart

richard@roguewavelimited.com
http://www.roguewavelimited.com
Reply With Quote
  #5  
Old 03-29-2009, 07:26 AM
 
rshandel rshandel is offline
 

Senior Member
  
Join Date: Feb 2009
Posts: 125
 

Default 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.
__________________
x-cart 4.1.12
x-cart 4.2
Reply With Quote
  #6  
Old 03-29-2009, 10:15 AM
  rogue's Avatar 
rogue rogue is offline
 

X-Adept
  
Join Date: Apr 2007
Location: Loveland, Ohio
Posts: 770
 

Default 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.
__________________
Richard Williams
Rogue Wave Limited

Initial Inventory Imports
Daily Inventory Updates
Daily Inventory Reports
Drop Ship Support
Order Export to Shipper/Supplier
Shopping Feeds That Work
Programming for X-Cart

richard@roguewavelimited.com
http://www.roguewavelimited.com
Reply With Quote
  #7  
Old 06-04-2009, 01:05 PM
 
mikalou mikalou is offline
 

Advanced Member
  
Join Date: Jun 2005
Posts: 71
 

Default 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');
__________________
X-Cart Gold 4.2.2 - 3.1.19
Reply With Quote
  #8  
Old 06-04-2009, 01:23 PM
 
mikalou mikalou is offline
 

Advanced Member
  
Join Date: Jun 2005
Posts: 71
 

Default Re: pass variable from 1 template to the other

Also should be
{/php}
__________________
X-Cart Gold 4.2.2 - 3.1.19
Reply With Quote
  #9  
Old 06-04-2009, 01:59 PM
 
rshandel rshandel is offline
 

Senior Member
  
Join Date: Feb 2009
Posts: 125
 

Default 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}
__________________
x-cart 4.1.12
x-cart 4.2
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 11:57 AM.

   

 
X-Cart forums © 2001-2020