如何在 opencart 2.0 的头文件 tpl 中插入模块?

How to insert module in header tpl file in opencart 2.0?

如何在 opencart 2.0 中的 header.tpl 文件中插入模块?

我有一个模块。没有该模块的布局位置选项。 所以我需要手动将其放入 header.tpl 文件中。

我已经 tried this 但没有为 opencart 2.0 工作。

请任何人帮助我。

谢谢

您的代码有误

$['special_block'] = $module = $this->getChild('module/special', array(
    'limit' => 5,
    'image_width' => 80,
    'image_height' => 80
));

opencart 2.0以上版本可以加载模块控制器:-

$data['anyname'] = $this->load->controller('modulefolder/filename');

并且在该模块的控制器文件中应该有一个 return 它 render.Like:

return $this->load->view('default/template/modulefolder/filename.tpl', $data);

例如,您在公共文件夹

下有一个名为 "testmodule" 的自定义模块

如果你想在header中插入这个模块你需要做以下事情

  1. 在 catalog/controller/common/header 上加载控制器。php

     $data['testmodule'] = $this->load->controller('common/testmodule');
    
  2. 在 header 模板文件中回显以下代码,即 view/theme/default/template/common/header.tpl

     <?php echo $testmodule; ?>
    

这会起作用