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

Getting PHP to work in Smarty Templates

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 10-08-2003, 10:05 AM
 
MiguelS MiguelS is offline
 

Advanced Member
  
Join Date: Sep 2003
Posts: 36
 

Default Getting PHP to work in Smarty Templates

Hopefully you guys can answer me this question like ASAP: Site's almost done.

Ok!
I have the clients image products setup in a table


http://www.trevinosphoto.com/store/customer/home.php?cat=262

and the actual image page setup as follows:

http://www.trevinosphoto.com/store/customer/product.php?productid=17146&cat=262&page=1

Now the customer...never being happy with what they have want a button the clicks next and previous.

Well i have the code written in php that (in theory) whould take them to the next product for that category.

It looks like this:

<?php
$pimg_counter;
$ppg_counter;
$nxt_page;
$productid_num;


if ( $pimg_counter >= 0 && $pimg_counter <= 8 )
{
$productid_num = $productid + 1;
$nxt_page = $page + 1;
$pimg_counter = $pimg_counter + 1;

echo "<a href=product.php?productid=".$productid_num."&cat= ".$cat."&page=".$page."&pimg_counter=".$pimg_count er.">NEXT IMAGE</a>
";
echo "<a href=home.php?cat=".$cat."&page=".$nxt_page.">NEXT PAGE</a>";
}

else
{

$productid_num = $productid + 1;
$nxt_page = $page + 1;
$pimg_counter = $pimg_counter + 1;

echo "<a href=product.php?productid=".$productid_num."&cat= ".$cat."&page=".$nxt_page."&pimg_counter=".$pimg_c ounter.">NEXT IMAGE</a>
";
echo "<a href=home.php?cat=".$cat."&page=".$nxt_page.">NEXT PAGE</a>";
}

?>


The only problem I have right now is that I can't get the include this PHP script into product.tpl

How can I include the above script into a smarty template?
Reply With Quote
  #2  
Old 10-08-2003, 03:10 PM
  adpboss's Avatar 
adpboss adpboss is offline
 

X-Man
  
Join Date: Feb 2003
Location: Ontario, Canada
Posts: 2,389
 

Default

This forum is for posting custom mods.

If you would like a response to this post, try moving it to "Template Editing".

I am sure you will get help there.
Reply With Quote
  #3  
Old 10-09-2003, 05:53 AM
 
MiguelS MiguelS is offline
 

Advanced Member
  
Join Date: Sep 2003
Posts: 36
 

Default

sorry, i thought it qualified as a mod. thanks for the move.
Reply With Quote
  #4  
Old 10-09-2003, 07:23 AM
  groovico's Avatar 
groovico groovico is offline
 

X-Man
  
Join Date: Apr 2003
Location: Firetanksoftware.com
Posts: 2,326
 

Default

use the smarty {php} {/php} tags to include php code within templates.

I don't think your product code is going to be so simple, remember the client can re-order the products in the category, reverse list them, disable certain products etc etc. Your code needs to take into account all of those, the product ID isn't static either, if the customer deletes a product it no longer exists on the database and that product ID will show a blank.

Also watch it doesnt affect the static catalog generation.
__________________
Groovico

Used by X-carters the world over:
Marketing Manager Pro Bundle For X-cart
Featured Product Manager for X-cart
Feed manager pro for X-cart

http://www.firetanksoftware.com

Celebrating 7 Years of providing quality X-cart Add ons and X-cart Mods for x-cart 3.X to X-cart 4.4.X
Reply With Quote
  #5  
Old 10-09-2003, 11:13 AM
 
MiguelS MiguelS is offline
 

Advanced Member
  
Join Date: Sep 2003
Posts: 36
 

Default

I tried those tags and they give me a parse error. I thought it was the php script declare tag, but i tried both <? or <?php and neither helped.

I tried just doing a simple echo and that also gave me a parse error.

It doesn't give me an error when i place just the php tags ({php}{/php}) but i definatley get an error when ever i place any php code in between them.

If my code does not work does anybody have any suggestions? i don't see how it will not. it will grab the current productid from withinside the product.tpl file. same for the current category and current page.

I'd understand if i declared an if else statement and used a constant productid and constant cat (like i am doing for a certain template but that's another issue.) but the productid increment is to whatever the value of productid is currently.

thanks for the help thus far. You guys are great.


ADDITIONAL NOTE: Just to be a bit more clear.

{php}
<? ?>
{/php}
OR
{php}
<?php ?>
{/php} <-------------- parse error.

{php}
{/php}<--------------- No parse error (but not very useful)
Reply With Quote
  #6  
Old 10-10-2003, 07:13 AM
 
MiguelS MiguelS is offline
 

Advanced Member
  
Join Date: Sep 2003
Posts: 36
 

Default

Ok i found my answer in the smarty website.

Now i have a new questions if anyone can help. How can I pass the current variables of that page over to my php script.

For instance i rely on the current value of the variables $page $cat $productid for my script to work. How can i transfer this information to my php script?

I had to use the {include_php} tage but the info on the smarty site isn't very extensive. any help would be appreciated, thanks.
Reply With Quote
  #7  
Old 10-10-2003, 07:16 AM
  adpboss's Avatar 
adpboss adpboss is offline
 

X-Man
  
Join Date: Feb 2003
Location: Ontario, Canada
Posts: 2,389
 

Default

Please share your solution with us.
Reply With Quote
  #8  
Old 10-10-2003, 07:38 AM
  nlindahl's Avatar 
nlindahl nlindahl is offline
 

Member
  
Join Date: Aug 2003
Location: Edmonton, AB, Canada
Posts: 28
 

Default

There's a function built into the smarty class that allows you to fetch template variables.

Quote from the smarty documentation:
Quote:
array get_template_vars(string [varname]);
This returns the given assigned variable value. If no parameter is given, an array of
all assigned variables is returned.

Example : get_template_vars
// get assigned template var Б─≥fooБ─≥
$foo = $smarty->get_template_vars(Б─≥fooБ─≥);
// get all assigned template vars
$tpl_vars = $smarty->get_template_vars();
// take a look at them
print_r($tpl_vars);
__________________
Nick
Running various versions of X-Cart Gold in various locations...
(when I have time, I\'ll make them all current, but by then x-cart 5.x.x will probably be out....)
Reply With Quote
  #9  
Old 10-10-2003, 11:08 AM
 
MiguelS MiguelS is offline
 

Advanced Member
  
Join Date: Sep 2003
Posts: 36
 

Default

That's not exactly what i'm looking for.

OK, i think i sorta semi solved how to do this: THE PROBLEM now is that for some reason $productid and $page have no value inside the actual product details page.

I need to somehow get the value of $productid and $page from the previous location (which is the home.tpl) into product.tpl so that my equation can work.

this is what i got so far.

what i have to do is make an if else statement using smarty's actual tags.

So have thus far.

{if ( $pimg_counter >= 0 && $pimg_counter <= 8 )

NEXT

NEXT PAGE


{else}
NEXT

NEXT PAGE

{/if}

HOWEVER i now have a NEW problem.

The problem is that once you are actually viewing the product details there is no value in either $productid or $page which i definatley need.

I'm wondering is there a tag that will get the actual variable from the url....
Reply With Quote
  #10  
Old 10-10-2003, 12:14 PM
 
MiguelS MiguelS is offline
 

Advanced Member
  
Join Date: Sep 2003
Posts: 36
 

Default

ALRIGHT i'm getting closer here, maybe with a bit more help i can figure this out.

ok, now i have my NEXT button working very simple code indeed.

so far so good.

Ok i made a .tpl file called nextpage.tpl

and this is the code in that file:

NEXT


All to easy yes?

but in order to get the variable for productid in there i needed this:

{include file="../files/master/nextpage.tpl" productid=$product.productid}

in the product.tpl file, where productid is assigned $product.productid and transfered to my template.


All very good and well BUT utterly useless because here's the deal:

If i were to just use this simple code i would wind up in a problem when i reach the end of the ProductID list.

So i came up with a solution but i've hit another brick wall with it.



Here's my solution maybe the X-cart supermods can help me with the answer:

I need to use if statements but i need to learn how to grab the variables that I need.

Here's my plan see if anybody can give me a hand:


$total_products = $AmountOfProductsInCurrentCategory

$product_counter

if $product_counter <= $total_products - 1

Show NEXT button
$product_counter = $product_counter + 1

else $product_counter = $total_products

Show Goto Home Button

All I really need to know is how to get the total amount of products for the current category.

I thought it was this line of text:

{ $subcategories[cat_num].product_count } but as it turns out it's not, (well it maybe) but there is no value inside of it when placed inside the product.tpl file.

If anybody, just anybody can show me how to get the the total amount of products inside the current category i could do the rest myself.

I appreciate all your guys help and i'll pose the code and every thing once i'm done with this.
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 03:57 PM.

   

 
X-Cart forums © 2001-2020