Jump to content

Custom hook for CMS page always displays at top


mtimedia

Recommended Posts

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.
 

 

 

What am I doing wrong?

Edited by mtimedia (see edit history)
Link to comment
Share on other sites

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...