首页 > 解决方案 > 为什么我不能在 prestashop 1.7 的主题中嵌入我的模板?

问题描述

我正在尝试遵循 prestashop 的官方指南,但我面临两个问题:

  1. 我将 display.tpl 视为原始文本,而不是嵌入到主题中。
  2. 我看不到存储在变量“my_module_message”中的消息

g2a.php(主模块文件)

public function hookDisplayLeftColumn($param)
{
    $this->context->smarty->assign(
        array(
            'my_module_name' => configuration::get('G2A_NAME'),
            'my_module_link' => $this->context->link->getModuleLink('g2a','display'),
            'my_module_message' => $this->l('This is a simple text message')));

    return $this->display(__FILE__ , 'g2a.tpl');
}

控制器/前端/display.php

class g2adisplayModuleFrontController extends ModuleFrontController
{
  public function initContent()
  {
    parent::initContent();
     $this->context->smarty->assign('my_module_message', $this->l('This is a simple text message'));
        $this->setTemplate('module:g2a/views/templates/front/display.tpl');
  }
}

视图/模板/front/display.tpl

    {extends file=$layout}

{block name='content'}
  welcome to my shop!
  {$my_module_message}
{/block}

标签: phpmoduleprestashopsmarty

解决方案


代码中的所有内容都是正确的,但是因为我在管理面板中禁用了缓存,所以我认为这不是缓存问题。

管理>配置>高级参数>性能> Smarty >模板编译>如果文件已更新,则重新编译模板


推荐阅读