A theme in OpenCartA free open-source CMS for online stores, written in PHP with a MySQL/MariaDB database. Everything that is not part of the core is added through extensions. More in the glossary → is structurally a set of Twig templates, styles, and images from which the storefrontWhat the customer sees: the home page, categories, product page, and cart. More in the glossary → 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/, 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. Here we cover only what concerns the storefront.
| What | OpenCart 3.0 | OpenCart 4.1 |
|---|---|---|
| Core templates | catalog/ | catalog/ |
| Main CSS | catalog/ | catalog/ (alongside bootstrap.css and SCSS sources) |
| Theme images | catalog/ | no separate theme folder |
| Shared JS libraries | catalog/ (jQuery, Bootstrap, Font Awesome) | catalog/ (jQuery, Bootstrap, common.js) |
| Extension templates | in the theme: template/ | extension/ |
| 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 controllerCode that receives a request and prepares data. More in the glossary → 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 pageThe page for a single product: photos, price, options, description, reviews. More in the glossary → is in product/.
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/ for the view/*/before event with priority 500, meaning it runs before rendering each storefront template. The logic is as follows:
- It checks that the theme selected in the store settings (
config_theme) is enabled. For this, thetheme_{код}_statuskey is used. If the theme is not enabled, the storefront stops with an error that no theme is assigned to the store. - The folder is determined. For the
defaulttheme, the folder name is taken fromtheme_default_directory; for other themes, it equals the theme code. - If the folder is not
defaultand contains the{папка}/file, that file is used. Otherwise,template/ {маршрут}.twig default/is used.template/ {маршрут}.twig - Finally, the
themetable is checked: if there is code saved in the editor for this route and theme, that code is rendered.
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/.
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/, 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/. 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
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/ 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.

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/on disk, deploy, and nothing changes on the site, because the old copy for this route is stored in the database;product.twig - 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.

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/, 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/, and your theme has its own copy of product/, 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.
In 4.1, template modifications are processed by event/ on the same view/*/before event, but with priority 0, meaning earlier than the theme editor. The article about OCMOD in OpenCart 4.1 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 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_widthbelong to the theme and are configured in its form under "ExtensionsAdditional functionality: a module, a payment or shipping method, a feed, or a theme. They are managed in "Extensions → Extensions." More in the glossary → → Extensions → Themes." Storefront controllers read them astheme_{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 asconfig_image_thumb_widthand 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. - 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
$thisand->document ->addStyle() addScript(), and the header outputs them in a loop. If you remove this loop from your ownheader.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.
Summary
- OpenCart 3.0: the theme is a folder in
catalog/view/theme/, andevent/themetakes the file from it or fromdefault. Inheritance works at the level of the whole file. - OpenCart 4.1: base templates live in
catalog/, and the theme as an extension redirectsview/ template/ $routeto its own files throughview/*/before. - The theme editor stores code in the
themetable, 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. Other articles on markup and front-end are collected in the section templates and front-end.