简体   繁体   English

home.tpl中的OpenCart变量

[英]OpenCart variables in home.tpl

So i'm trying to display the categories on the homepage in a custom theme of OpenCart. 因此,我试图以OpenCart的自定义主题在首页上显示类别。

In the header.tpl you can use variables as $categories and so fort, but when I want to use these variables in the home.tpl file, it says it doesn't exists. 在header.tpl中,可以将变量用作$categories等,但是要使用,但是当我要在home.tpl文件中使用这些变量时,它说它不存在。

Is there any way to make these variables working in the home.tpl file? 有什么办法可以使这些变量在home.tpl文件中工作? I can't find any line in the header.tpl that includes a PHP files where all these variables can be found. 我在header.tpl中找不到任何包含可以找到所有这些变量的PHP文件的行。

You need to look into the controller of header.tpl called header.php In there, you can find the part where categories is assigned ( line 93 to 124 ) 您需要查看header.tpl的标题为header.php的控制器,在其中可以找到分配了categories的部分( 第93至124行

Paste this part into the home.php ( on line 18 ) 将此部分粘贴到home.php中第18行

Now the variable categories is available. 现在,变量categories可用。

(1) search in common/header.php @ class ControllerCommonHeader for the code fragment that constructs categories array, in my project (v 1.5.5.1) I have it like that (1)在我的项目(v 1.5.5.1)中,在common/header.php @ class ControllerCommonHeader搜索构建类别数组的代码片段,我有这样的感觉

 $this->data['categories'] = array(); $categories = $this->model_catalog_category->getCategories(0); foreach ($categories as $category) { ... 

(2) Copy that code snippet to common/home.php @ class ControllerCommonHome @ function index() , now you can use it in home.tpl (2)将代码片段复制到common/home.php @ class ControllerCommonHome @ function index() ,现在可以在home.tpl使用它了

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

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