Reputation: 241
In Prestashop not able to get Header and Footer in the Custom Module Created for the FrontOffice
Also not able to add the theme.css file with the way $this->context->controller->addCSS('path');
Main Module File testmodule.php
<?php
if (!defined('_PS_VERSION_'))
exit;
/* @var boolean error */
protected $_errors = false;
public function __construct()
{
$this->name = 'testmodule';
$this->tab = 'front_office_features';
$this->version = '1.0';
$this->author = 'Nemo';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('testmodule');
$this->description = $this->l('Adds a block.');
$this->confirmUninstall = $this->l('Are you sure you want to delete this module?');
//$this->context->controller->addCSS($this->_path.'testmodule/css/testmodule.css', 'all');
}
public function hookDisplayHeader()
{
$this->context->controller->addCSS('\themes\PRS01\assets\css\theme.css','all');
$this->context->controller->addCSS($this->_path.'css/testmodule.css', 'all');
}
public function initContent(){
parent::initContent();
$this->addCSS('\themes\PRS01\assets\css\theme.css');
$this->setTemplate('allproducts.tpl');
}
public function install()
{
if (!parent::install() &&
!$this->registerHook('header'))
return false;
return true;
}
public function uninstall()
{
if (!parent::uninstall())
return false;
return true;
}
public function countAllProducts()
{
return Db::getInstance()->getValue('SELECT COUNT(*) from ps_product WHERE active = 1');
}
}
Controller File:
<?php
Class testmoduleAllproductsModuleFrontController extends ModuleFrontController
{
public function init(){
$this->page_name = 'allproducts';
//$this->display_column_left = false;
parent::init();
}
public function setMedia()
{
parent::setMedia();
$this->context->controller->addCSS('\themes\PRS01\assets\css\theme.css', 'all');
}
public function initContent(){
// parent::initContent();
// echo "hello";
// $this->setTemplate('allproducts.tpl');
//$this->context->controller->addCSS('/js/jquery/ui/jquery-ui.css');
parent::initContent();
$products_partial = Product::getProducts($this->context->language->id, 0, 5, 'name', 'asc');
$products = Product::getProductsProperties($this->context->language->id, $products_partial);
$this->context->smarty->assign(array(
'products' => $products,
'homeSize' => Image::getSize('home_default'),
'HOOK_HEADER' => Hook::exec('displayHeader')
));
//$this->setTemplate('allproducts.tpl');
// setMedia();
$this->context->controller->addCSS('\themes\PRS01\assets\css\theme.css');
//$this->addCSS('themes\PRS01\assets\css\theme.css');
$this->setTemplate('module:testmodule/views/templates/front/allproducts.tpl');
$this->addCSS('module:testmodule/css/testmodule.css');
//return $this->display(__FILE__,'views/templates/front/allproducts.tpl');
}
}
.tpl file to show the module
<h1> Hello World </h1>
Upvotes: 1
Views: 1890
Reputation: 31
You should try to extends your tpl file as page, you can change tpl file content like this then it's display header and footer too.
{extends file='page.tpl'}
{block name='page_content'}
Your Codes
{/block}
Upvotes: 3