Ovi Posted August 18, 2010 Share Posted August 18, 2010 I have been searching the forum up and down but i couldn't get any solution working..I'm trying to display different HTML code in "header.tpl" depending of the parent category i'm in, this should work for both subcategories pages and product pages.. Ideally i need something along this lines: {if $category == 37}HTML info 1 {elseif $category == 45}HTML info 2 {else}default HTML info{/if} where $category is the Parent ID of the subcategory/product page i'm currently browsing.Can this be done? Many many thanks in advance. Link to comment Share on other sites More sharing options...
rocky Posted August 19, 2010 Share Posted August 19, 2010 Unfortunately, there is no parent category variable available in PrestaShop, so your only option is to modify PrestaShop to add it. Edit header.php and add the following code before the $smarty->display: if (isset($_GET['id_category']) AND $_GET['id_category'] > 0) { $category = new Category($_GET['id_category']); if (Validate::isLoadedObject($category)) $smarty->assign('id_parent', $category->id_parent); } You can then use the following code in header.tpl: {if $id_parent == 45} Your code here {/if} Link to comment Share on other sites More sharing options...
Ovi Posted August 19, 2010 Author Share Posted August 19, 2010 Thanks very much for the help rocky, your method seems to detect PARENT minus 1 level though.I'm having the following structure:Home > Parent category (id=44) > Subcategory (id=45) > Subcategory1 (id=45) > PRODUCTThis works: {if $id_parent == 45} text here {/if} Hower this: {if $id_parent == 44} text here {/if} doesn't work.Any ideas how can i detect a level up?Next time i'm having balance in my PayPal account i'm going to donate at the "donate" link in your site for all the help you provide over here, you should put a "donate" link in your sig though, you deseve it! Link to comment Share on other sites More sharing options...
Ovi Posted August 25, 2010 Author Share Posted August 25, 2010 Ignore my last post, i didn't get it the first time But i'm having a big issue, the IF statements work while browsing categories but don't work while looking at a product page, just noticed this and it's a big problem .. any clue ? Help please !it seems like i need to also get the Parent_ID of the product? Link to comment Share on other sites More sharing options...
rocky Posted August 26, 2010 Share Posted August 26, 2010 You are correct. You'll need to check the id_product too. Try the following code: if (isset($_GET['id_category']) AND $_GET['id_category'] > 0) $category = new Category($_GET['id_category']); elseif (isset($_GET['id_product']) AND $_GET['id_product'] > 0) { $product = new Product($_GET['id_product']); $category = new Category($product->id_category_default); } if (isset($category) AND Validate::isLoadedObject($category)) $smarty->assign('id_parent', $category->id_parent); There already is a Donate link on the menu at the top of my site. Is it not obvious enough? Link to comment Share on other sites More sharing options...
Ovi Posted August 26, 2010 Author Share Posted August 26, 2010 Works like a charm, thank you! Link to comment Share on other sites More sharing options...
Kaihaku Posted August 26, 2010 Share Posted August 26, 2010 Thanks, I also found this very helpful. Do you think there's any chance of that edit to header.php being added to the official distribution? Link to comment Share on other sites More sharing options...
rocky Posted August 26, 2010 Share Posted August 26, 2010 I think it is unlikely, but you can post a feature request on the bug tracker. Link to comment Share on other sites More sharing options...
Kaihaku Posted August 27, 2010 Share Posted August 27, 2010 That's unfortunate, this would be a helpful little feature for skinning in general. I'll add it to feature request, crediting the code to you of course, and hope that it's accepted. Link to comment Share on other sites More sharing options...
manuxo Posted February 18, 2011 Share Posted February 18, 2011 Hello!Rocky i have a doubt!I'm doing a website that in header.tpl it's included one Div that contains Flash.swf file!I'd like to know if is it possible to load multiple *.tpl files depending on the Category ID.I've been searching on this forum and i found mutiples post's that teach how to load multiples header's.jpg and backgrounds.The function that i found here is: Are there a way to say something like this:<{_PS_BASE_DIR}={$theme_dir}header{if $category == xxx OR $category == xxx}{$category}{/if}.tpl>???Wating an answer!Regards from Portugal!Mano Link to comment Share on other sites More sharing options...
rocky Posted February 18, 2011 Share Posted February 18, 2011 So you want to include a different template for each category from category.tpl? Try the following: {include file="$tpl_dir./header$id_category.tpl"} Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now