Jeform Posted December 29, 2016 Share Posted December 29, 2016 Je cherche à travailler avec 2 templates différents pour présenter mes catégories. je pense qu'une utilisation de if else et des includes smarty pourrait bien faire l'affaire, mais je sèche sur la syntaxe. voici en résumé ce que je souhaite faire : Si je charge une des categories dont l'ID est [1 ou 2 à_ 3] alors j'utilise le template category1.tpl sinon j'utilise le template par defaut category.tpl Si un passionné de smarty veut bien m'expliquer la syntaxe ? merci par avance Link to comment Share on other sites More sharing options...
Olivier CLEMENCE Posted December 31, 2016 Share Posted December 31, 2016 Hello, pas sûr que ce soit dans smarty qu'il faut faire ça. Le plus propre serait dans ton controller catégorory. Tu rajoute la condition. if(category == 1 || 2 ou 3) { charger le template category1.tpl } else charger le template category normal } 1 Link to comment Share on other sites More sharing options...
Mediacom87 Posted December 31, 2016 Share Posted December 31, 2016 Bonjour, je présume que tu cherche à faire ta condition dans un tpl. donc {if $id-category == 1 || $id-category == 2 || $id-category == 3} {include 'category1.tpl'} {else} {include 'default_category.tpl'} {/if} Link to comment Share on other sites More sharing options...
Jeform Posted January 8, 2017 Author Share Posted January 8, 2017 Merci , je vais tester ces 2 solutions et vous faire mon retour. Link to comment Share on other sites More sharing options...
Jeform Posted January 11, 2017 Author Share Posted January 11, 2017 Je viens d'essayer ceci dans mon controller category mais sans succes ??un conseil ? /** * Initializes page content variables */ public function initContent() { parent::initContent(); if ($category->id == 3) { $this->setTemplate(_PS_THEME_DIR_.'category2.tpl'); } else { $this->setTemplate(_PS_THEME_DIR_.'category.tpl'); } if (!$this->customer_access) { return; } if (isset($this->context->cookie->id_compare)) { $this->context->smarty->assign('compareProducts', CompareProduct::getCompareProducts((int)$this->context->cookie->id_compare)); } Link to comment Share on other sites More sharing options...
Gnast Posted January 12, 2017 Share Posted January 12, 2017 Il ne faut pas oublier de suprimer class_index.php dans le dossier cache et aussi de "forcer la compilation des tpl" dans le BO si tu fais des modifications dans le tpl Link to comment Share on other sites More sharing options...
Jeform Posted January 14, 2017 Author Share Posted January 14, 2017 Oui c'est fait, mais pas de résultat... le code vous semble correct ? merci Link to comment Share on other sites More sharing options...
BeComWeb Posted January 16, 2017 Share Posted January 16, 2017 Je viens d'essayer ceci dans mon controller category mais sans succes ?? un conseil ? public function initContent() { parent::initContent(); if ($category->id == 3) { $this->setTemplate(_PS_THEME_DIR_.'category2.tpl'); } else { $this->setTemplate(_PS_THEME_DIR_.'category.tpl'); } Essayez plutôt avec $this->category->id. et effectivement si vous travaillez en override (ce qui est plus que recommandé), il faut penser à supprimer le fichier "class_index.php" 1 Link to comment Share on other sites More sharing options...
Jeform Posted January 16, 2017 Author Share Posted January 16, 2017 Essayez plutôt avec $this->category->id. et effectivement si vous travaillez en override (ce qui est plus que recommandé), il faut penser à supprimer le fichier "class_index.php" C'est exactement cela merci beaucoup 1 Link to comment Share on other sites More sharing options...
BeComWeb Posted January 16, 2017 Share Posted January 16, 2017 De rien. Pensez à passer le topic en "[Résolu]" 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