Opencart - 在 .tpl 中包含 .tpl
我正在使用 opencart 开源电子商务网站。我遇到的主要问题是当我尝试将面包屑分离到包含在每个 .tpl 文件中的单个文件中时。我尝试过使用基本的 PHP include 方法,尽管这不起作用。
回复 Jay 的回答:
我创建了一个新的面包屑控制器,用于呈现单独的面包屑模板文件。
<代码> class ControllerCommonBreadcrumb extends Controller {
public function index() {
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/breadcrumbs.tpl')) {
$this->template = $this->config->get('config_template') . '/template/common/breadcrumbs.tpl';
} else {
$this->template = 'default/template/common/breadcrumbs.tpl';
}
$this->render();
}
}
?>
虽然这会导致错误:
Notice: Undefined variable: breadcrumbs
I am using the opencart open source e-commerce website. The main problem I am having is when I try to separate the breadcrumbs into a single file that I include inside each .tpl file. I have tried using the basic PHP include method although this does not work.
In Reply to Jay's answer:
I have created a new breadcrumbs controller that renders the separate breadcrumb template file.
<?php
class ControllerCommonBreadcrumb extends Controller {
public function index() {
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/breadcrumbs.tpl')) {
$this->template = $this->config->get('config_template') . '/template/common/breadcrumbs.tpl';
} else {
$this->template = 'default/template/common/breadcrumbs.tpl';
}
$this->render();
}
}
?>
Although this causes the error:
Notice: Undefined variable: breadcrumbs
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,您需要首先使用 $this->children 将面包屑模板设置为控制器操作的子项,然后用它回显面包屑。您还需要设置面包屑控制器的 id,以便您知道在模板中回显什么内容,
我个人只是将面包屑添加到 common/header.tpl 文件中,这要容易得多
To do this, you need to first set the breadcrumb template as a child of the controller action using $this->children, then echoing out the breadcrumbs with that. You will also need to set the id of the breadcrumb controller, so that you know what to echo in your template
Personally I would just add the breadcrumbs to the common/header.tpl file instead, it's far easier