If you want to create a custom page in opencart, there are two ways to do it :
1. You can go into the information section using the admin area.
2. You can create a controller file for your page, which points to a few other pages.
In codeigniter you would create a controller and a view and if setup was needed, we would create some rules in the routes file. This application is just a bit different.
Thankfully, this is a really simple task in OpenCart web Development.
How to create a custom page in OpenCart:
You need to create a controller for your file, naming based on the folder and filename. For instance common/home.php Has the class initialization like this :
Class ControllerCommonHome extends Controller
This is accessed using index.php?route=common/home and accesses the index() method.
If you want to call another method, for instance bananas, you would need to define the method as
public function bananas() {
// Code here
}
and we would call it using index.php?route=common/home/bananas.
Now, we need to render the view. Simply add all of the following code to the end of your controller method :
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') .
'/template/common/new_template_file.tpl')) {
$this->template = $this->config->get('config_template') .
'/template/common/new_template_file.tpl';
} else {
$this->template = 'default/template/common/new_template_file.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
Which will render the following :
/catalog/view/theme/your-theme-name/template/common/new_template_file.tpl
If that file doesn’t exist, it will attempt to use the same path in the default theme folder.
Take a look at a few controllers and templates to get your head around where everything comes from properly, but that’s the basic gist of how creating a custom page in OpenCart works.
We hope that you have enjoyed our short post in OpenCart Web Development. Stay tuned …
Tags:custom page in opencart, Houston opencart development, Opencart web development






