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

Problems passing PHP variables to Smarty templates

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 01-05-2004, 02:37 PM
 
NuAlpha NuAlpha is offline
 

X-Adept
  
Join Date: Aug 2003
Location: US
Posts: 598
 

Default Problems passing PHP variables to Smarty templates

I have created the file "query_parse.php" in the customer directory. Inside that file is the following:
Code:
<?PHP $arg_value = explode("=", $_SERVER['QUERY_STRING']); $smarty = new Smarty; $smarty->assign("argval", $arg_value[1]); // value of the URL argument ?>

I am trying to display certain tabs at the top of my site by using the category of the product being displayed using the following code in head.tpl:

Code:
{ include_php file="../customer/query_parse.php" } { if $argval eq "" } { include file="topnavtabs/top_nav_tabs_01.tpl" } { elseif $argval eq "3" } { include file="topnavtabs/top_nav_tabs_02.tpl" } {/if}

Every time I now try to load my site I always receive the error "Fatal error: Call to a member function on a non-object in query_parse.php on line 3".

The variable churns out the correct number each time if I remove the "smarty->assign" line and replace that with a "print($arg_value)", so I know that I am getting the information I need. I just can't get it into the template I am using.

I have going over and over documentation of PHP and Smarty for the last 4 hours and am at my wits end to explain why I can't pass this variable. I am new to both PHP and Smarty so please bare with me.

Thanks,
Joshua

NOTE: I moved this post from the board "Program Logic" today, this was originally posted on January 4th.
Reply With Quote
  #2  
Old 01-05-2004, 02:43 PM
 
NuAlpha NuAlpha is offline
 

X-Adept
  
Join Date: Aug 2003
Location: US
Posts: 598
 

Default

Somehow, and for no apparent reason, the problem has stopped giving me the "non-object" error after I 'required' the Smarty.class.php, but any attempt to reload my pages after a change in the template says I can't redeclare a certain variable (sorry, forget name).

Also, I still cannot get variables created in a PHP document to pass into a Smarty template. Any PHP variables or Smarty variables created in a PHP document always contain nothing when inside a template. Variables I assign in a template also don't hold their data no matter what I put in them using the syntax ->
Code:
{assign var="foo" value="bar"}

This is most frustrating.

If anyone can please enlighten me as to what is going on I would appreciate it.
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 08:00 AM.

   

 
X-Cart forums © 2001-2020