https://stackoverflow.com/questions/45542726/opencart-3-x-including-a-new-template-file
To add your own custom twig file and include it inside another existing one you need to do three things:
- Create the actual custom twig file. In your case it will be:
catalog/view/theme/customtheme/template/common/header_home.twig
- Create a controller for that twig file. In your case you can just copy:
/catalog/controller/common/header.php
and rename that toheader_home.php
. Edit this controller and change the class name toControllerCommonHeaderHome
usually on line 2. - Lastly, since you are going to include
header_home
insidehome.twig
, edit/catalog/controller/common/home.php
and add the line$data['header'] = $this->load->controller('common/header_home');
after$data['header'] = $this->load->controller('common/header');
That’s it. After you’ve done the steps above, you can now include {{ header_home }}
inside home.twig
. If you are editing the files directly, I find that sometimes I need to login to the admin of the website, go to design>theme editor, open up the files I added or changed, hit reset, and save. Refresh your website and you should see the changes.