cocodeluxe Posted May 8, 2014 Share Posted May 8, 2014 (edited) Hi and thanks for the support I've been watching this code in this tutorial http://nemops.com/page-specific-prestashop-module/#.U2uiz_l_uAW if('category' != $this->context->controller->php_self) return false; and I would need to know if there is a conditional determined for a category id or something thanks and regards Edited May 10, 2014 by vekia (see edit history) Link to comment Share on other sites More sharing options...
Krystian Podemski Posted May 8, 2014 Share Posted May 8, 2014 You should look at Dispatcher.php class Link to comment Share on other sites More sharing options...
cocodeluxe Posted May 8, 2014 Author Share Posted May 8, 2014 You should look at Dispatcher.php class Thanks for the comment sorry I've been looking but I need something more specific to start Link to comment Share on other sites More sharing options...
cocodeluxe Posted May 8, 2014 Author Share Posted May 8, 2014 Nemo show me the light Tools::getValue('id_category') == THE_ONE_TO_CHECK I made the statement in this way but not work public function hookDisplayBanner($params) { if ( Tools::getValue('id_category') == 4 $this->context->controller->php_self) return false; return $this->hookDisplayTop($params); } What can I do with this ? thanks Link to comment Share on other sites More sharing options...
vekia Posted May 9, 2014 Share Posted May 9, 2014 if ( Tools::getValue('id_category') == 4 $this->context->controller->php_self) this statement is wrong. use this one instead: if ( Tools::getValue('id_category') == 4 ) it means "if id_category=4 then do sometihng" or use this one if ( Tools::getValue('id_category') != 4 ) if id category is not 4 then do something Link to comment Share on other sites More sharing options...
cocodeluxe Posted May 9, 2014 Author Share Posted May 9, 2014 very thanks vekia Link to comment Share on other sites More sharing options...
cocodeluxe Posted May 9, 2014 Author Share Posted May 9, 2014 (edited) I tried this conditional to display the contents of a module in a single category in this way, blocklinks module public function hookLeftColumn($params) { if ( Tools::getValue('id_category') != 4 ) return false; } $links = $this->getLinks(); $this->smarty->assign(array( 'blocklink_links' => $links, 'title' => Configuration::get('PS_BLOCKLINK_TITLE', $this->context->language->id), 'url' => Configuration::get('PS_BLOCKLINK_URL'), 'lang' => 'text_'.$this->context->language->id )); if (!$links) return false; return $this->display(__FILE__, 'blocklink.tpl'); } it´s right? Edited May 9, 2014 by cocodeluxe (see edit history) Link to comment Share on other sites More sharing options...
cocodeluxe Posted May 9, 2014 Author Share Posted May 9, 2014 Any review please Link to comment Share on other sites More sharing options...
vekia Posted May 9, 2014 Share Posted May 9, 2014 hello, it's wrong. you missed open bracket after if condition. let me know something you want to display something when category id = 4 or you want to display something when category id is not equal to 4 ? Link to comment Share on other sites More sharing options...
cocodeluxe Posted May 9, 2014 Author Share Posted May 9, 2014 hello, it's wrong. you missed open bracket after if condition. let me know something you want to display something when category id = 4 or you want to display something when category id is not equal to 4 ? Only display in category id =4 Thanks Link to comment Share on other sites More sharing options...
vekia Posted May 9, 2014 Share Posted May 9, 2014 so you have to use this: public function hookLeftColumn($params) { if (isset($_GET['id_category'])){ if (Tools::getValue('id_category') == 4){ $links = $this->getLinks(); $this->smarty->assign(array( 'blocklink_links' => $links, 'title' => Configuration::get('PS_BLOCKLINK_TITLE', $this->context->language->id), 'url' => Configuration::get('PS_BLOCKLINK_URL'), 'lang' => 'text_'.$this->context->language->id )); if (!$links) return false; return $this->display(__FILE__, 'blocklink.tpl'); } } } Link to comment Share on other sites More sharing options...
cocodeluxe Posted May 9, 2014 Author Share Posted May 9, 2014 (edited) Very thanks vekia and to exclude a category id.:? Thanks again Edited May 9, 2014 by cocodeluxe (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted May 9, 2014 Share Posted May 9, 2014 what you mean? you want to not run this code when someone browse category (category you want to exclude) ? Link to comment Share on other sites More sharing options...
cocodeluxe Posted May 9, 2014 Author Share Posted May 9, 2014 I wanted to say that the content appears in all least one , for example excluided category id =5. I said before about a !=5 and return false or something in the above example I can use multiple ids. 4,5, 6. ? if (Tools::getValue('id_category') == 4) Very thanks Link to comment Share on other sites More sharing options...
vekia Posted May 9, 2014 Share Posted May 9, 2014 code above will display content only on category page == 4 if you want to HIDE it only on category == 5 just use !=5 instead of ==5 and yes, you can use many conditions there if ($something == 1 || $something2==2 || $something3 == 3){ do something } || means "OR" Link to comment Share on other sites More sharing options...
cocodeluxe Posted May 9, 2014 Author Share Posted May 9, 2014 the lesson is over Very thanks master Link to comment Share on other sites More sharing options...
vekia Posted May 10, 2014 Share Posted May 10, 2014 you're welcome :-) glad to hear that i could help you a little i marked topic title as solved. with regards, MIlos Link to comment Share on other sites More sharing options...
cocodeluxe Posted May 10, 2014 Author Share Posted May 10, 2014 sorry for reopen it´s posible this: if (Tools::getValue('id_category') == 3 ||('id_category') == 4){ Link to comment Share on other sites More sharing options...
Krystian Podemski Posted May 10, 2014 Share Posted May 10, 2014 Hello, The best way to do this is this code because there is no need to use isset for notice errors etc. public function hookLeftColumn($params) { $categoriesArray = array(3,4,5,6,8,9); $currentCategory = Tools::getValue('id_category', 0); if(in_array($currentCategory, $categoriesArray) { $links = $this->getLinks(); $this->smarty->assign(array( 'blocklink_links' => $links, 'title' => Configuration::get('PS_BLOCKLINK_TITLE', $this->context->language->id), 'url' => Configuration::get('PS_BLOCKLINK_URL'), 'lang' => 'text_'.$this->context->language->id )); if (!$links) return false; return $this->display(__FILE__, 'blocklink.tpl'); } } Link to comment Share on other sites More sharing options...
vekia Posted May 10, 2014 Share Posted May 10, 2014 sorry for reopen it´s posible this: if (Tools::getValue('id_category') == 3 ||('id_category') == 4){ this code is wrong, code below is proper one if (Tools::getValue('id_category') == 3 || Tools::getValue('id_category') == 4){ Link to comment Share on other sites More sharing options...
cocodeluxe Posted May 10, 2014 Author Share Posted May 10, 2014 Hello, The best way to do this is this code because there is no need to use isset for notice errors etc. public function hookLeftColumn($params) { $categoriesArray = array(3,4,5,6,8,9); $currentCategory = Tools::getValue('id_category', 0); if(in_array($currentCategory, $categoriesArray) { $links = $this->getLinks(); $this->smarty->assign(array( 'blocklink_links' => $links, 'title' => Configuration::get('PS_BLOCKLINK_TITLE', $this->context->language->id), 'url' => Configuration::get('PS_BLOCKLINK_URL'), 'lang' => 'text_'.$this->context->language->id )); if (!$links) return false; return $this->display(__FILE__, 'blocklink.tpl'); } } With this code i have a Parse error: syntax error, unexpected '{' in /customers/0/0/7/lonelite.com/httpd.www/modules/blocklink/blocklink.php on line 121 Link to comment Share on other sites More sharing options...
cocodeluxe Posted May 10, 2014 Author Share Posted May 10, 2014 this code is wrong, code below is proper one if (Tools::getValue('id_category') == 3 || Tools::getValue('id_category') == 4){ Like a charm very thanks again Link to comment Share on other sites More sharing options...
Krystian Podemski Posted May 10, 2014 Share Posted May 10, 2014 Oh, read the warnings, there is one ) missed here: if(in_array($currentCategory, $categoriesArray) should be if(in_array($currentCategory, $categoriesArray)) this code is much cleaner and easier to manage Link to comment Share on other sites More sharing options...
cocodeluxe Posted May 10, 2014 Author Share Posted May 10, 2014 Oh, read the warnings,there is one ) missed here:if(in_array($currentCategory, $categoriesArray)should beif(in_array($currentCategory, $categoriesArray))this code is much cleaner and easier to manage Very thanks 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