2017-06-01 37 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}