Prestashop无法在为FrontOffice创建的自定义模块中获取页眉和页脚
也无法以$ this-> context-> controller-> addCSS('path');
的方式添加theme.css文件主模块文件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');
}
}
控制器文件:
<?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文件以显示模块
<h1> Hello World </h1>
答案 0 :(得分:2)
您应该尝试将tpl文件扩展为页面,您可以像这样更改tpl文件内容,然后显示页眉和页脚。
{extends file='page.tpl'}
{block name='page_content'}
Your Codes
{/block}