# OpenCart Theme: Directory Structure and Template Selection in 3.0 and 4.1

> Where the templates, styles and scripts of OpenCart 3.0 and 4.1 themes live, how the core chooses a template file, and why themes in 4.1 work completely differently.

Джерело: https://opencartcode.com/en/wiki/dev-themes/opencart-theme-structure
OpenCart: 3.0, 4.1
Оновлено: 2026-11-25

A theme in [OpenCart](https://opencartcode.com/en/wiki/glossary/e-commerce-glossary#opencart) is structurally a set of Twig templates, styles, and images from which the [storefront](https://opencartcode.com/en/wiki/glossary/e-commerce-glossary#storefront) builds its HTML. In 3.0, a theme is a separate folder in `catalog/view/theme/`, and the core takes the file from there. If the file is missing, it falls back to `default`. In 4.1 there are no theme folders: base templates live in `catalog/view/template/`, and a theme is an extension that overrides the needed templates through events.

Examples are for OpenCart 4.1; in 4.0.x, model triggers and event handling differ. This article describes how everything is organized. Creating your own theme and connecting JS/CSS in modules will be covered in separate articles in this section.

## Where do theme files live in OpenCart 3.0 and 4.1?

The difference between the branches starts at the directory level, so first compare the file trees. The full directory map is in the article [about the file structure of OpenCart 3.0 and 4.1](https://opencartcode.com/en/wiki/dev-architecture/opencart-file-structure). Here we cover only what concerns the storefront.

| What | OpenCart 3.0 | OpenCart 4.1 |
| --- | --- | --- |
| Core templates | `catalog/view/theme/default/template/` | `catalog/view/template/` |
| Main CSS | `catalog/view/theme/default/stylesheet/stylesheet.css` | `catalog/view/stylesheet/stylesheet.css` (alongside `bootstrap.css` and SCSS sources) |
| Theme images | `catalog/view/theme/default/image/` | no separate theme folder |
| Shared JS libraries | `catalog/view/javascript/` (jQuery, Bootstrap, Font Awesome) | `catalog/view/javascript/` (jQuery, Bootstrap, `common.js`) |
| Extension templates | in the theme: `template/extension/{тип}/` | `extension/{код}/catalog/view/template/` |
| Alternative themes | a sibling folder in `catalog/view/theme/` | an extension of type theme in `extension/{код}/` |

Inside `template/` the structure is the same: subfolders by storefront section, and each template corresponds to a [controller](https://opencartcode.com/en/wiki/glossary/e-commerce-glossary#controller) route. In 3.0 these are `account`, `affiliate`, `checkout`, `common`, `error`, `extension`, `information`, `mail`, `product`. In 4.1 there is no `affiliate` and `extension`, but `cms` has appeared. The header and footer in both branches live in `common/header.twig` and `common/footer.twig`, and the [product page](https://opencartcode.com/en/wiki/glossary/e-commerce-glossary#product-page) is in `product/product.twig`.

The path to CSS in the header is set differently. In 3.0, the link to `stylesheet.css` is written directly in `header.twig` of the default theme, along with the folder name. In 4.1, the paths to `bootstrap.css`, icons, `stylesheet.css`, and jQuery are generated by the `common/header` controller and passed to the template as variables. So to change the main CSS in 4.1, editing the template is not enough: you need to change the controller data, for example through an event.

## How does OpenCart 3.0 choose a template file?

In 3.0, the choice is made by the `event/theme` handler. It is registered in `system/config/catalog.php` for the `view/*/before` event with priority 500, meaning it runs before rendering each storefront template. The logic is as follows:

1. It checks that the theme selected in the store settings (`config_theme`) is enabled. For this, the `theme_{код}_status` key is used. If the theme is not enabled, the storefront stops with an error that no theme is assigned to the store.
2. The folder is determined. For the `default` theme, the folder name is taken from `theme_default_directory`; for other themes, it equals the theme code.
3. If the folder is not `default` and contains the `{папка}/template/{маршрут}.twig` file, that file is used. Otherwise, `default/template/{маршрут}.twig` is used.
4. Finally, the `theme` table is checked: if there is code saved in the editor for this route and theme, that code is rendered.

```mermaid
flowchart TD
    A["load->view('product/product')"] --> B["event/theme: is theme enabled?"]
    B -->|"no"| X["Error: no theme assigned"]
    B -->|"yes"| C["Is there a file in the theme folder?"]
    C -->|"yes"| D["Template from the theme folder"]
    C -->|"no"| E["Template from default"]
    D --> F["Is there a record in the theme table?"]
    E --> F
    F -->|"yes"| G["Render code from the editor"]
    F -->|"no"| H["Render file"]
```

Hence the main property of the 3.0 theme: **inheritance at the file level**. In your own theme folder you can keep only the templates you actually changed; the rest will be pulled from `default`. This is not Twig block inheritance but a complete replacement of the file. If you copy `common/header.twig`, change one line, and then update OpenCart, your copy will not receive the changes brought by the update to the header.

The selection logic is the same in 3.0.4.1 and 3.0.5.1. The rendering itself in 3.0 reads the file from `DIR_TEMPLATE`, and when OCMOD is enabled, it first looks for a modified copy in `storage/modification/catalog/view/theme/`.

## What is a "theme" in OpenCart 4.1?

In 4.1, there is no `catalog/view/theme/` directory at all. Base storefront templates live in `catalog/view/template/`, and it is these that the core renders. The default theme is an `basic` extension from the `extension/opencart/` package. Its settings in the admin panel consist effectively of a single status toggle, and the default value of `config_theme` is also `basic`.

The `event/theme` handler in 4.1 also hangs on `view/*/before` with priority 500, but it does less than in 3.0. It only looks in the `theme` table for the active theme editor record for the current store and route and substitutes its code. It checks neither the theme status nor the folder. In the storefront code of 4.1.0.4, `config_theme` is not read at all: this value is used by admin settings, while template substitution is handled by the theme extension itself.

Substitution works as follows. During startup, the storefront registers, for each installed extension, a template namespace `extension/{код}` that points to `extension/{код}/catalog/view/template/`. The `view/*/before` event in 4.1 receives the `[&$route, &$data, &$code, &$output]` arguments, and the modified `$route` is used for rendering. Thus, the theme redirects the route to its own file:

Example

```php
namespace Opencart\Catalog\Controller\Extension\MyTheme\Event;

class Theme extends \Opencart\System\Engine\Controller {
    public function index(string &$route, array &$data, string &$code, string &$output): void {
        if (!$this->config->get('theme_my_theme_status') || $this->config->get('config_theme') != 'my_theme') {
            return;
        }

        // Беремо файл теми лише тоді, коли він існує; решта йде з catalog/view/template/
        if (is_file(DIR_EXTENSION . 'my_theme/catalog/view/template/' . $route . '.twig')) {
            $route = 'extension/my_theme/' . $route;
        }
    }
}
```

The event with the `catalog/view/*/before` trigger is registered in the extension's install. The `config_theme` check in the handler is mandatory, because otherwise the theme will also run when a different one is selected in the settings. How such handlers work is covered in detail in the article [about event view and view/*/before](https://opencartcode.com/en/wiki/dev-events-ocmod/event-view-opencart).

Extensions → Extensions → Themes: here the theme is enabled and its status is set · OpenCart 4.1.0.4

## How does the theme editor work, and why is it risky?

The editor at Design → Theme Editor (Design → Theme Editor) does not change files on disk. It saves the modified template code to the `theme` table, and the `event/theme` handler substitutes this code in place of the file. The record is tied to the store and route, and in 3.0 also to the theme folder. In 4.1 the record has a status field, and only active records are used.

Because of this scheme, the editor is convenient for quick fixes on a live site, but it has non-obvious consequences:

- an edit made in the editor takes priority over the file. You change `product/product.twig` on disk, deploy, and nothing changes on the site, because the old copy for this route is stored in the database;
- in 3.0, records are tied to the theme folder, so after switching to another theme the edits disappear, and they reappear after switching back;
- code in the database does not end up in git and is not updated together with OpenCart;
- editor content is rendered as a string, so a Twig syntax error there breaks the page just as it would in a file.

> If changes to a template "are not applied," first check the `theme` table for this route, and only then the cache. In 3.0, the record is reset or deleted in the editor; in 4.1 it is deleted in the editor's list, and the core takes only records with status 1.

Design → Theme Editor: templates saved here take priority over files · OpenCart 4.1.0.4

## How do OCMOD and the Twig cache affect templates?

Between the template file and the finished HTML there are two more layers, and both are often confused with the "theme."

### OCMOD

In 3.0, modifications write modified copies of files to `storage/modification/`, and Twig rendering takes the template from there if a copy exists. A modification is tied to a specific path. If a module changes `catalog/view/theme/default/template/product/product.twig`, and your theme has its own copy of `product/product.twig`, your file is used, and the module's change will not appear on the site. That is why module authors often write paths with a mask for all themes, while theme developers check which OCMOD changes need to be carried over into their copies. The syntax and masks are described in the article [about OCMOD syntax in 3.0](https://opencartcode.com/en/wiki/dev-events-ocmod/ocmod-syntax).

In 4.1, template modifications are processed by `event/modification.view` on the same `view/*/before` event, but with priority 0, meaning earlier than the theme editor. The article [about OCMOD in OpenCart 4.1](https://opencartcode.com/en/wiki/dev-events-ocmod/ocmod-opencart-4) explains how OCMOD in 4.1 differs from 3.0.

### Compiled template cache

In both branches, Twig compiles templates into PHP files in the `template/` subfolder of the cache directory (`DIR_CACHE`) with `auto_reload` enabled, so a change to the file on disk is usually picked up automatically. The cache should be cleared after mass changes and after working with OCMOD, not after every edit. The article [about the storage directory](https://opencartcode.com/en/wiki/dev-architecture/opencart-storage) describes what is kept in storage and what can be deleted.

## What does the theme change besides templates?

The theme is not just Twig. Part of what the customer sees is set by settings, and where these settings live differs between branches.

- **Image sizes.** OpenCart 3.0: keys like `theme_default_image_thumb_width` belong to the theme and are configured in its form under "[Extensions](https://opencartcode.com/en/wiki/glossary/e-commerce-glossary#extensions) → Extensions → Themes." Storefront controllers read them as `theme_{config_theme}_image_…`, so a new theme must store its own set of these keys, otherwise resizing will receive empty width and height values. OpenCart 4.1: sizes have been moved to general settings as `config_image_thumb_width` and so on, and the theme has no effect on them. How the files are resized afterward is described in the article [about model tool/image](https://opencartcode.com/en/wiki/dev-practice/resize-opencart).
- **Number of products and description length in listings.** In 3.0, these are also theme keys (`theme_default_product_limit`, `theme_default_product_description_length`).
- **Module styles and scripts.** Modules add their own CSS/JS through `$this->document->addStyle()` and `addScript()`, and the header outputs them in a loop. If you remove this loop from your own `header.twig`, modules will lose their styles.
- **Language strings.** Template texts come from the language files of the controllers, not from the theme, so the theme should not hardcode Ukrainian or English strings in Twig.

Because of front-end libraries, templates cannot be moved between branches as-is: the 3.0 storefront is built on Bootstrap 3, while 4.1 uses Bootstrap 5, and the class markup differs significantly. General approaches to code that works with both versions are gathered in the article [about compatibility with 3.0 and 4.1](https://opencartcode.com/en/wiki/dev-practice/opencart-module-compatibility-3-4).

## Summary

- OpenCart 3.0: the theme is a folder in `catalog/view/theme/`, and `event/theme` takes the file from it or from `default`. Inheritance works at the level of the whole file.
- OpenCart 4.1: base templates live in `catalog/view/template/`, and the theme as an extension redirects `$route` to its own files through `view/*/before`.
- The theme editor stores code in the `theme` table, and this code overrides the file. This is the first place to check when an edit "does not work."
- OCMOD in 3.0 is tied to the file path, so your own copy of a template in the theme can "eat" a module's change.
- In 3.0, image sizes belong to the theme; in 4.1, they are in general settings.

Next, it is worth understanding how Twig receives variables from the controller, in the article [about Twig in OpenCart](https://opencartcode.com/en/wiki/dev-mvc/opencart-twig-templates). Other articles on markup and front-end are collected in the section [templates and front-end](https://opencartcode.com/en/wiki/dev-themes).

## FAQ

**In 3.0, can I keep only a few modified templates in my theme?**

Yes. If a file is missing from your theme folder, event/theme takes it from default, so the theme only needs to store the modified templates. Keep in mind that these copies are not updated along with OpenCart.

**Why did the design of some pages disappear after moving the site to another server?**

Most often, some of the edits lived in the theme editor, that is, in the theme table, and only the files were moved. Another reason: in 3.0, storage/modification was not copied, so the modifications need to be refreshed.

**Can I use a 3.0 theme in 4.1?**

Not directly: the directory structure is different, the template selection mechanism is different, and it uses Bootstrap 5 instead of Bootstrap 3. The markup will need to be adapted, and the theme itself should be packaged as a 4.1 extension.

**Where do I find the module template on the 4.1 storefront?**

In the extension folder: extension/{код}/catalog/view/template/, and the route in the controller is written as extension/{код}/module/name.
