Creating a Custom Page in OpenCart 1.5 (viewtopic.php?f=23&t=59542)
Creating a Custom Page in OpenCart 2 (viewtopic.php?f=23&t=136937)
What you need:
- Basic PHP knowledge
- Basic HTML knowledge
- Text Editor
Required files to create a custom page:
- Controller file
- Template file
Optional files:
- Model file
- Language file (I will be using it in this example here)
Controller file
Create a file name 'static.php' in /catalog/controller/information/
Code: Select all
<?php
class ControllerInformationStatic extends Controller {
public function index() {
// Optional. This calls for your language file
$this->load->language('information/static');
// Optional. Set the title of your web page
$this->document->setTitle($this->language->get('heading_title'));
// Breadcrumbs for the page
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home')
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('information/static')
);
// Get "heading_title" from language file
$data['heading_title'] = $this->language->get('heading_title');
// All the necessary page elements
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
// Load the template file and show output
$this->response->setOutput($this->load->view('information/static', $data));
}
}
Create a file name 'static.twig' in /catalog/view/theme/default/template/information/
Code: Select all
{{ header }}
<div id="information-information" class="container">
<ul class="breadcrumb">
{% for breadcrumb in breadcrumbs %}
<li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
{% endfor %}
</ul>
<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 }}
<h1>{{ heading_title }}</h1>
{{ content_bottom }}</div>
{{ column_right }}</div>
</div>
{{ footer }}
Create a file name 'static.php' in /catalog/language/english/information/
Code: Select all
<?php
// Heading
$_['heading_title'] = 'Static Page';
// Add as many as you want, but remember to call for it in the controller file before you can use it in the template
$_['my_text'] = 'My Text';