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

New template

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 03-29-2003, 11:18 AM
 
maniac maniac is offline
 

Advanced Member
  
Join Date: Mar 2003
Posts: 97
 

Default New template

I finally figured out how to pass variables from php to smarty, however I'm stuck on one thing.

Here's what I did:

1. Created a simple php file that runs through a MySQL query and brings back a series of items from a news table - the db and table I'm accesing is totally independent from x-cart.

2. created a new smarty template that displays a simple table within my customer/home.tpl file.

What I want to do:

display the sql query file in the new smarty template I created.

What do I need to do to the php file?

What do I need to do to the smarty template file?

What do I need to do to the home.php and home.tpl files?

I have managed to pass all the variables I use on the sql query to the smarty template, I defined those in home.php ($smarty->asign...), I just can't get the smarty template to display the results of the query.

Thanks in advance.
Reply With Quote
  #2  
Old 03-31-2003, 05:01 AM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

if for instance your php file had a query in it like:

$results=func_query(blah blah);

$smarty->assign("myquery",$results);

You need to access the elements of the results array similar to the way it is done with products or categories

ie
include the file:
{ include file="mytemplate.tpl" }

then put in a section:
{section name=myquery loop=$myquery}

then within this section (dont forget to close it at the end) put in something like:

{$myquery.fieldname}

or something fairly similar.
__________________
ex x-cart guru
Reply With Quote
  #3  
Old 04-04-2003, 07:50 PM
 
maniac maniac is offline
 

Advanced Member
  
Join Date: Mar 2003
Posts: 97
 

Default

OK, I'll give it a shot,

Thanks for the info...
Reply With Quote
  #4  
Old 04-14-2003, 08:42 AM
 
maniac maniac is offline
 

Advanced Member
  
Join Date: Mar 2003
Posts: 97
 

Default

OK,

I've moved much further along. The query is being executed and bringing back the resutls I want (I echoed them from the query and they showed up on my page), However, they are not displaying in the template file I have created. Right now I have this is my template file:

{section name=news loop=$newsItems}
Title: {$newsItems.title}

{/section}

this is my php file:

<?
$dbCon=mysql_connect("host","user","pass") or die("Could not connect to the database");
mysql_select_db($dBName,$dbCon);

$SQLCon="SELECT title,ID,description,category,date FROM articles WHERE visible = 1 AND date<=NOW() AND category<>10 ORDER BY date DESC, ID DESC LIMIT 7 ";
$newsItems=mysql_query($SQLCon);

//while ($rs=mysql_fetch_array($newsItems))
// {
// echo "$rs[title] | $rs[date]
\n";
// echo "$rs[description]\n";
// echo "

\n";
// }

$smarty->assign("newsItems",$newsItems);

?>


Thanks again...
Reply With Quote
  #5  
Old 04-14-2003, 08:49 AM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

sorry had a small typo in my message - i have now corrected it. doh!

$smarty->assign("myquery",$results);
__________________
ex x-cart guru
Reply With Quote
  #6  
Old 04-14-2003, 09:43 AM
 
maniac maniac is offline
 

Advanced Member
  
Join Date: Mar 2003
Posts: 97
 

Default

Quote:
Originally Posted by funkydunk
sorry had a small typo in my message - i have now corrected it. doh!

$smarty->assign("myquery",$results);

Figured it out

Still, see my message above, I'm getting closer and closer to it...
Reply With Quote
  #7  
Old 04-16-2003, 03:21 PM
 
maniac maniac is offline
 

Advanced Member
  
Join Date: Mar 2003
Posts: 97
 

Default

I give up.

no matter what I do i can't ge the results to show up on my template...

I've tried mimicking the producs query, but still no progress..

Please help.
Reply With Quote
  #8  
Old 04-16-2003, 11:15 PM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

Okay,

your php script should be:

Code:
<? // amendments by funkydunk.net 2003 // this file to be included in customer/home.php using include "./thisscript.php"; $SQLCon = "SELECT title,ID,description,category,date FROM articles WHERE visible = 1 AND date<=NOW() AND category<>10 ORDER BY date DESC, ID DESC LIMIT 7 "; $newsItems = func_query($SQLCon); $smarty->assign("newsItems",$newsItems); ?>

This shoudl be included in customer/home.php

Then in your template:

Code:
{section name=news loop=$newsItems} Title: {$newsItems.title} {/section}
should be changed to:

Code:
{section name=news loop=$newsItems} Title: {$newsItems[news].title} {/section}
__________________
ex x-cart guru
Reply With Quote
  #9  
Old 04-17-2003, 07:13 AM
 
maniac maniac is offline
 

Advanced Member
  
Join Date: Mar 2003
Posts: 97
 

Default You Rock!

Thanks Funky!

That worked like a charm and did exactly what I needed. I REALLY REALLY APPRECIATE your help, with it, I've learned lots along the way...

I'll post a URL when the site is finished.

Thanks again!
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



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:31 PM.

   

 
X-Cart forums © 2001-2020