2017-06-01 109 views
1

进来的Prestashop不能够得到页眉和页脚中的自定义模块创建的FrontOffice页眉和页脚都没有的Prestashop前端模块

也不能添加theme.css文件与方式$这个 - >上下文>控制器 - > addCSS( '路径');

主要模块文件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

你是如何解决这个问题的? –

+0

在您的前端模块模板(.tpl)文件中写入{extends file ='page.tpl'}它会给您的主题页眉,页脚和自定义页面布局。这是Prestashop 1.7的解决方案。 请查看任何一个现有的前端模块模板文件,例如themes \ classic \ templates \ customer \ my-account.tpl,并查看它们的实现,他们也是这样做的。 –

+0

感谢@Honey Thakuria –

回答

0

你应该尝试扩展您的TPL文件页面,你可以像这样改变tpl文件内容,那么它也是显示页眉和页脚。

{extends file='page.tpl'} 
{block name='page_content'} 
    Your Codes 
{/block}