Opencart - How to manually display a module inside a template file?

Let's say I want to display a special module on the main page in a position other than $ content_top, $ content_bottom, $ column_left or $ column_right. How can I do it? If you have some experience with this, could you give me some pointers?

The module will be displayed in home.tpl, but I assume that I will need to edit the controller file home.php

+4
source share
1 answer

To do this, you need to make changes to two files

First, you will need to edit the controller. In this example, I'm going to add special offers to my homepage.

So open the controller file catalog/controller/common/home.php . Somewhere before this line $this->response->setOutput($this->render()); add the following

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

An array is the settings for the module. Please note that the location, position, status and sort order are not included, as they are irrelevant here. I also used special_block as a unique key for the content, in order to avoid its conflict with any other elements that may need to be rendered

Then in your template file you just need to use <?php echo $special_block; ?> <?php echo $special_block; ?> wherever you want the module to be

+9
source

Source: https://habr.com/ru/post/1390427/


All Articles