opencart-如何在模板文件中手动显示模块? [英] opencart - How to manually display a module inside a template file?

查看:37
本文介绍了opencart-如何在模板文件中手动显示模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我想在主页上的特殊模块中显示与$ content_top,$ content_bottom,$ column_left或$ column_right不同的位置.我怎么做?如果您有一些经验,可以给我一些指导吗?

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?

该模块将显示在home.tpl中,但我假设我需要编辑控制器文件home.php

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

推荐答案

为此,您需要对两个文件进行编辑

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

因此打开控制器文件catalog/controller/common/home.php. $this->response->setOutput($this->render());这行之前的某处添加以下内容

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

阵列是模块的设置.请注意,其中不包含布局,位置,状态和排序顺序,因为它们与此处无关.我还使用special_block作为内容的唯一键,以避免它与可能需要渲染的任何其他项目冲突

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

然后,在您的模板文件中,只需要将<?php echo $special_block; ?>放到要放置模块的位置即可

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

这篇关于opencart-如何在模板文件中手动显示模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆