mtimedia Posted October 27, 2013 Share Posted October 27, 2013 (edited) I have successfully added a new module with a new hook to a specific cms page. However, when I load the page the module, and I'm assuming the hook, is displayed at the very top of every cms page. I created a CmsController.php in the override/controllers/front folder with the following code. class CmsController extends CmsControllerCore { public function process() { parent::process(); self::$smarty->assign('HOOK_PORTFOLIO', Module::hookExec(portfolio, $params)); } } In the cms.tpl for my theme I have added the following code in after {$cms->content} : {if $smarty.get.id_cms==4} {$HOOK_PORTFOLIO} {/if} This works great, except for the hook being displayed on every cms page at the very top. (After <body> but before any css or js files). The hook is displayed at the correct place on page id 4 and doesn't get displayed on the other cms pages. http://www.mtimedia.com/en/content/4-portfolio What am I doing wrong? Edited October 27, 2013 by mtimedia (see edit history) Link to comment Share on other sites More sharing options...
gonebdg - webindoshop.com Posted October 29, 2013 Share Posted October 29, 2013 Do you have a reason why you put the custom hook (HOOK_PORTFOLIO) on public function process() instead on public function initContent() ? Link to comment Share on other sites More sharing options...
mtimedia Posted October 29, 2013 Author Share Posted October 29, 2013 No. One of the tutorials I was referencing used process(). I change it to initContent() but I get the same result. Link to comment Share on other sites More sharing options...
mtimedia Posted October 29, 2013 Author Share Posted October 29, 2013 For some reason the <head> content is also being placed in the <body> tags with the new hook first. Link to comment Share on other sites More sharing options...
gonebdg - webindoshop.com Posted October 30, 2013 Share Posted October 30, 2013 Try to delete file /cache/class_index.php first And make sure the content which placed inside HOOK_PORTOFOLIO is a valid HTML content just curious ... what you've placed inside HOOK_PORTFOLIOif it's just a static HTML content, then you can place it straight to cms.tpl file without have to develop a module. Link to comment Share on other sites More sharing options...
vekia Posted October 30, 2013 Share Posted October 30, 2013 well, i think that in cms editor page you can define everything, also fancybox gallery etc more hooks, modules = worst performance Link to comment Share on other sites More sharing options...
mtimedia Posted October 30, 2013 Author Share Posted October 30, 2013 I deleted the class_index.php each time I changed something in the override folder. The code for the hook is: portfolio.tpl <!-- Portfolio --> {$table} portfolio.php (the actual content generation code) public function hookPortfolio{$params) { $pagename = pathinfo($_SERVER['REQUEST_URI'], PATHINFO_FILENAME); $rows = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT * FROM '._DB_PREFIX_.'portfolio' ); $table = '<ul>'; // Get menu for the page foreach($rows as $row){ // Create a cell $table .= '<div class="pfcell">'; // Check what category it is and choose the correct action switch ($row['category']) { case 'Logos': $table .= '<a href="' . $row['filepath'] . '" target="_blank">'; break; case 'Website': $table .= '<a href="' . $row['filepath'] . '" target="_blank">'; break; default: // No action } // Get the image for the cell $table .= '<img class="images" src=' . $row['thumbnailpath'] . '>'; // Get the cell hover color $table .= '<div class="imgbg"></div>'; // Get the image information $table .= '<div class="imginfo"> <span class="imgInfoText top">' . $row['name'] . '</span> <span class="imgInfoText bottom">' . $row['category'] . '</span> </div>'; // Close the cell $table .= '</a></div>'; } $table .= '</ul>'; echo $table; $this->smarty->assign('table', $table); global $smarty; return $this->display(__FILE__,'portfolio.tpl'); } So it basically just creates an unordered list of images and links. Nothing fancy. @Vekia: So is there already something similar in the cms editor? I was planning on making a backend admin part for the module so I won't have to worry about maintaining it. I'm making the website for someone else. Link to comment Share on other sites More sharing options...
mtimedia Posted October 30, 2013 Author Share Posted October 30, 2013 I think I just figured it out. I left the echo statement in there from when it was its own page. I'll take it out when I get home and that should fix the problem. That would explain why it shows up before anything else and why it shows up on all cms pages. 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