Search code examples
opencartopencart2.xopencart-3

How to show another header template at home page?


I have get an header.twig file. I need to display this header template in home page differently than in others pages. How to do that?


Solution

  • Make two files, header.twig and home_header.twig

    In catalog/controller/common/header.php there is a function index(), this uses header.twig

    Write another method for example index_home() in header.php and copy the index() body in this function (make any changes if needed)

    In index_home() change

    return $this->load->view('common/header', $data);
    

    to

    return $this->load->view('common/home_header', $data);
    

    If you check functions of every controller there is a line

    $data['header'] = $this->load->controller('common/header');
    

    this will call header.twig Whichever function you need to use home_header.twig you can replace

    $data['header'] = $this->load->controller('common/header');
    

    in that function with

    $data['header'] = $this->load->controller('common/header/index_home');
    

    This will use home_header.twig