简体   繁体   中英

OpenCart variables in home.tpl

So i'm trying to display the categories on the homepage in a custom theme of 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.

Is there any way to make these variables working in the home.tpl file? I can't find any line in the header.tpl that includes a PHP files where all these variables can be found.

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 )

Paste this part into the home.php ( on line 18 )

Now the variable categories is available.

(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

 $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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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