Themes About OpenCart Themes OpenCart uses MVC architecture. This means that the V or view is kept separate from the main code. The viewis made up of the *.tpl files and are always found in: catalog/view/theme/YOUR_THEME/*.* tpl files are
Themes
About OpenCart Themes
OpenCart supports multiple catalog themes. There are many themes available from the contributions are as well as commercially. You can also choose to create your own theme.
How to Create a new Theme
There are some golden rules to follow when creating your own theme.
When upgrading, your theme should be untouched. Any new changes in the default template will be shown while using your template with the exception of any changes to the files that you've customized. For example, if the catalog/view/theme/default/template/common/header.tpl file was changed, then you will need to make the small adjustments to the one in your theme. But that is much easier than trying to recreate your theme.
Modules
OpenCart utilizes a Model-View-Controller (MVC) structure. MVC separates code by concern, allowing developers to maintain and extend small segments of code specific to a given function verses a plethora of nested, interdependent files. It is highly recommended that you familiarize yourself with the form and function of MVC before proceeding to modify and extend OpenCart. For more information regarding MVC, please refer to Wikipedia .
We start with the files that are needed in order to create your module.
For the admin div: admin/controller/module/module_name.php admin/language/english/module/module_name.php admin/view/template/module/module_name.tplFor the front end(if required by your module): catalog/controller/module/module_name.php catalog/language/english/module/module_name.php catalog/view/theme/default/template/module/module_name.tpl |
The above are the main files that would be used by your module, so in total 6 files. Next, we should touch on each one and explain in simple terms what they are used for.
This is the controller file for the admin div. For those of you who
are not familiar with the use of this file, I will try to explain it
clearly here. This file is the building block or your module (admin and
catalog). This file does not produce anything to the end user, it
'constructs' the data that will be passed to the view file. Essentially,
the controller is a PHP class and nothing more.
So what must you do to create this controller file? First you need to
start the class:
ModuleName extends Controller { private $error = array(); public function index() { }} ?> |
That is the basis of your Controller. Now you have the use of the built
in error control and the start of your modules controller. Of course
this will not work without it having us enter the rest of the code. Not
to mention, what language file should be used, how is this module going
to be displayed...still a few more steps!
So let's get back to the basics of your admin controller.
ModuleName extends Controller { private $error = array(); public function index() { $this->load->language('module/modulename'); // THIS IS LOCATED UNDER YOUR ADMIN DIRECTORY $this->document->title = $this->language->get('heading_title'); }} ?> |
Now what we have done here is said that there is a language file
located in admin/language/module/modulename.php. Notice that with the
PHP Framework you do not need to include the .php. Next we are grabbing
the 'heading_title' from the language file so that it stores the title
in document->title(which will be used in the view of your module).
Moving on...if you want to utilize any of the built in OpenCart
features make sure to include the following in your code (which is
admin/controller/setting/setting.php):
ModuleName extends Controller { private $error = array(); public function index() { $this->load->language('module/modulename'); // THIS IS LOCATED UNDER YOUR ADMIN DIRECTORY $this->document->title = $this->language->get('heading_title'); $this->load->model('setting/setting'); }} ?> |