简体   繁体   English

Opencart-在.tpl内包含.tpl

[英]Opencart - Include .tpl inside of .tpl

I am using the opencart open source e-commerce website. 我正在使用opencart开源电子商务网站。 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. 我遇到的主要问题是,当我尝试将面包屑分离成单个文件时,该文件包含在每个.tpl文件中。 I have tried using the basic PHP include method although this does not work. 我尝试使用基本的PHP包含方法,尽管这不起作用。

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

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. 为此,您首先需要使用$ this-> children将面包屑模板设置为控制器操作的子代,然后用该方法回显面包屑。 You will also need to set the id of the breadcrumb controller, so that you know what to echo in your template 您还需要设置面包屑控制器的ID,以便您知道在模板中要回显的内容

Personally I would just add the breadcrumbs to the common/header.tpl file instead, it's far easier 我个人只是将面包屑添加到common / header.tpl文件中,这要容易得多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM