How to insert module in header tpl file in opencar

2019-08-10 21:03发布

问题:

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

I have a module. Does not have the layout position option for that module. So i need to place that manually in header.tpl file.

I am already tried this but not working for opencart 2.0.

Please any one help me.

Thanks

回答1:

In opencart 2.0 or above you can load the contoller of module :-

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

And In that module's controller file there should be a return of what it render.Like:

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


回答2:

Your code is wrong

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


回答3:

For example you have a custom module named "testmodule" under common folder

if you want to insert this module in header you need to do following thing

  1. Load controller on catalog/controller/common/header.php

     $data['testmodule'] = $this->load->controller('common/testmodule');
    
  2. Echo the following code on header template file i.e. view/theme/default/template/common/header.tpl

     <?php echo $testmodule; ?>
    

This will work



标签: opencart2.x