| ||||||||||
![]() |
Shopping cart software Solutions for online shops and malls | |||||||||
![]() |
![]() |
|
X-Cart Home | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Getting PHP to work in Smarty Templates | ||||
![]() |
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
![]() 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? |
|||||||
#2
|
|||||||||
|
|||||||||
![]() 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. |
|||||||||
#3
|
|||||||
|
|||||||
![]() sorry, i thought it qualified as a mod. thanks for the move.
|
|||||||
#4
|
|||||||||
|
|||||||||
![]() 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 |
|||||||||
#5
|
|||||||
|
|||||||
![]() 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) |
|||||||
#6
|
|||||||
|
|||||||
![]() 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. |
|||||||
#7
|
|||||||||
|
|||||||||
![]() Please share your solution with us.
|
|||||||||
#8
|
|||||||||
|
|||||||||
![]() There's a function built into the smarty class that allows you to fetch template variables.
Quote from the smarty documentation: Quote:
__________________
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....) ![]() |
|||||||||
#9
|
|||||||
|
|||||||
![]() 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.... |
|||||||
#10
|
|||||||
|
|||||||
![]() 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. |
|||||||
|
|||
X-Cart forums © 2001-2020
|