sixthmind Posted February 29, 2012 Share Posted February 29, 2012 I am currently learning template variables and trying to understand how they work and what they mean. I've done a test on {$category->id_cms_category}, which I put in cms.tpl and I get a result 9, but when I put this in header.tpl or blockcms.tpl (left column), there is no results, it's blank. Can somebody please explain how this works and how I can get the same result in different .tpl file? Link to comment Share on other sites More sharing options...
El Patron Posted February 29, 2012 Share Posted February 29, 2012 in your .tpl file, put in {debug} and this will show you all the variable available to your .tpl file. Hope this helps. Link to comment Share on other sites More sharing options...
sixthmind Posted March 1, 2012 Author Share Posted March 1, 2012 thanks Elpatron for your reply. I am already using {debug}. That's how I find all the variables. But the question is how to make certain variables like $category, which is class, available also in header.tpl and blockcms.tpl and not only available in cms.tpl. Why can't I use certain variables everywhere? How does this work? I would be very happy if somebody explain this. I am also still learning smarty. Link to comment Share on other sites More sharing options...
El Patron Posted March 1, 2012 Share Posted March 1, 2012 Hi, I as well am learning. For .tpl files, you need to see the caller, typically a controller folder and class folder, this is where variables are pass to the tpl. Link to comment Share on other sites More sharing options...
sixthmind Posted March 1, 2012 Author Share Posted March 1, 2012 Ok, I understand class $category is not included in header.tpl and blockcms.tpl. I still need to figure out how to include it, so I can then use its variables. I wonder if I was meant to put this code in header.php or somewhere else: include_once("../classes/Category.php"); include_once("../classes/CMSCategory.php"); Link to comment Share on other sites More sharing options...
sixthmind Posted March 1, 2012 Author Share Posted March 1, 2012 I think the question is really how to assign $category class to for example header.tpl. Anybody please? Link to comment Share on other sites More sharing options...
El Patron Posted March 1, 2012 Share Posted March 1, 2012 Look at ProductController.php in folder controllers to see how $category is init and then passed to smarty .tpl. Sorry I have been on a train across Spain today so I've not been online. Now time for a beer and tapa. Link to comment Share on other sites More sharing options...
sixthmind Posted March 5, 2012 Author Share Posted March 5, 2012 Ok, may I ask why ProductController.php? Development guide says that this controller is used by product.php to get a product. $category is currently available in cms.tpl, so shouldn't I be looking at CMSController for something in there? well, i found this code in ProductController.php: /* Category */ $category = false; if (isset($_SERVER['HTTP_REFERER']) AND preg_match('!^(.*)\/([0-9]+)\-(.*[^\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) AND !strstr($_SERVER['HTTP_REFERER'], '.html')) { if (isset($regs[2]) AND is_numeric($regs[2])) { if (Product::idIsOnCategoryId((int)($this->product->id), array('0' => array('id_category' => (int)($regs[2]))))) $category = new Category((int)($regs[2]), (int)(self::$cookie->id_lang)); } elseif (isset($regs[5]) AND is_numeric($regs[5])) { if (Product::idIsOnCategoryId((int)($this->product->id), array('0' => array('id_category' => (int)($regs[5]))))) $category = new Category((int)($regs[5]), (int)(self::$cookie->id_lang)); } } if (!$category) $category = new Category($this->product->id_category_default, (int)(self::$cookie->id_lang)); if (isset($category) AND Validate::isLoadedObject($category)) { self::$smarty->assign(array( 'path' => Tools::getPath((int)$category->id, $this->product->name, true), 'category' => $category, 'subCategories' => $category->getSubCategories((int)self::$cookie->id_lang, true), 'id_category_current' => (int)$category->id, 'id_category_parent' => (int)$category->id_parent, 'return_category_name' => Tools::safeOutput($category->name) )); } else self::$smarty->assign('path', Tools::getPath((int)$this->product->id_category_default, $this->product->name)); self::$smarty->assign('return_link', (isset($category->id) AND $category->id) ? Tools::safeOutput(self::$link->getCategoryLink($category)) : 'javascript: history.back();'); So would I have to create a copy of controller in override folder and put something in there so that certain classes would be available in other template files as well? Link to comment Share on other sites More sharing options...
DrGren Posted March 27, 2012 Share Posted March 27, 2012 Hi sixthmind, Did you find a solution to this? I am having basically the same problem since I don't want to display the left column if the products belong to a certain category. However, smarty doesn't know about the $category variable at the moment it prints the left column. Did you solve it? And in that case would you care to share your solution? Thank you very much. Link to comment Share on other sites More sharing options...
DrGren Posted March 28, 2012 Share Posted March 28, 2012 On my part I solved this by using the $name variable instead of the $category (the category I am interested in contains only one product which is the one that needs a completely different layout). I tried to implement the code above from ProductController.php into FrontController.php but with no success. Couldn't understand how to modify the call to idIsOnCategoryId. Link to comment Share on other sites More sharing options...
sixthmind Posted March 30, 2012 Author Share Posted March 30, 2012 Hi DrGren I managed to resolve the problem with help from another forum. Somebody very kind explained to me how everything works here -> http://stackoverflow.com/questions/9565637/prestashop-variables-not-accessible-in-header-tpl-category-class-not-availabl Hope it helps you as well. Let me know how you get on. 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