opencart - 如何手动显示模板文件中的模块?

发布于 2024-12-26 02:17:43 字数 165 浏览 2 评论 0原文

假设我想在主页上与 $content_top、$content_bottom、$column_left 或 $column_right 不同的位置显示特价模块。我该怎么做?如果您有这方面的经验,可以给我一些指导吗?

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贵在坚持 2025-01-02 02:17:43

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

首先,您需要编辑控制器。在此示例中,我将向主页添加特价商品,

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

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

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

然后在模板文件中,您只需要使用 无论你想让模块去哪里

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文