Vlastni twig soubor


To add your own custom twig file and include it inside another existing one you need to do three things:

  1. Create the actual custom twig file. In your case it will be: catalog/view/theme/customtheme/template/common/header_home.twig
  2. Create a controller for that twig file. In your case you can just copy: /catalog/controller/common/header.php and rename that to header_home.php. Edit this controller and change the class name to ControllerCommonHeaderHome usually on line 2.
  3. Lastly, since you are going to include header_home inside home.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.