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)
-   -   New template (https://forum.x-cart.com/showthread.php?t=2078)

maniac 03-29-2003 11:18 AM

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.

funkydunk 03-31-2003 05:01 AM

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. :wink:

maniac 04-04-2003 07:50 PM

OK, I'll give it a shot,

Thanks for the info...

maniac 04-14-2003 08:42 AM

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...

funkydunk 04-14-2003 08:49 AM

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

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

maniac 04-14-2003 09:43 AM

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 :D

Still, see my message above, I'm getting closer and closer to it...

maniac 04-16-2003 03:21 PM

:( 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.

funkydunk 04-16-2003 11:15 PM

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}


maniac 04-17-2003 07:13 AM

You Rock!
 
:D 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!


All times are GMT -8. The time now is 11:17 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.