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

一世执手 提交于 2019-12-08 23:59:01

问题


Let's say I want to display the specials module on the homepage in a position different than $content_top, $content_bottom, $column_left or $column_right. How do I do that? If you have some experience with this, could you give me some pointers?

The module will be display in home.tpl but I'm assuming I would need to edit the controller file home.php


回答1:


To do this, you will need to make edits to two files

Firstly, you will need to edit the controller. In this example, I'm going to add the specials to the home page

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
));

The array is the settings for the module. Note that the layout, position, status and sort order aren't included, as they're irrelevant here. I've also used special_block as a unique key for the content, to avoid it conflicting with any other items that may need rendering

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



来源:https://stackoverflow.com/questions/8819839/opencart-how-to-manually-display-a-module-inside-a-template-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!