Search code examples
twigopencartopencart-3

OpenCart 3.x - including a new template file


I need to add a new OpenCart template file into another template file.

Essentially I've created a new head file in /theme/customtheme/template/common/ called "header_home.twig".

Then in home.twig, I've changed {{ header }} to say {{ header_home }}, but it's not displaying anything.

Basically, all I did was copy header.twig and rename it to header_home.twig, and put in "xxxxx" to see if it was calling the new file, which it's not. Instead, it's not displaying anything.

Here's what my home.twig now looks like:

{{ header_home }}
<div id="common-home" class="container">
  <div class="row">{{ column_left }}
    {% if column_left and column_right %}
    {% set class = 'col-sm-6' %}
    {% elseif column_left or column_right %}
    {% set class = 'col-sm-9' %}
    {% else %}
    {% set class = 'col-sm-12' %}
    {% endif %}
    <div id="content" class="{{ class }}">{{ content_top }}{{ content_bottom }}</div>
    {{ column_right }}</div>
</div>
{{ footer }}

I assume I'm somehow missing a step when it comes to adding a new template file? If someone could help me with adding in a new twig file, that would be fantastic.


Solution

  • I haven't learn OpenCart 3.x, but I guess you need to change

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

    to

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

    in catalog/controller/common/header.php.