簡體   English   中英

Opencart-在.tpl內包含.tpl

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

我正在使用opencart開源電子商務網站。 我遇到的主要問題是,當我嘗試將面包屑分離成單個文件時,該文件包含在每個.tpl文件中。 我嘗試使用基本的PHP包含方法,盡管這不起作用。

在回答周傑倫的回答:

我創建了一個新的面包屑控制器,該控制器呈現了單獨的面包屑模板文件。

<?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();
    }
}
?>

盡管這會導致錯誤:

Notice: Undefined variable: breadcrumbs

為此,您首先需要使用$ this-> children將面包屑模板設置為控制器操作的子代,然后用該方法回顯面包屑。 您還需要設置面包屑控制器的ID,以便您知道在模板中要回顯的內容

我個人只是將面包屑添加到common / header.tpl文件中,這要容易得多

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM