Creating a Custom Page in OpenCart 1.5 (viewtopic.php?f=23&t=59542)
Creating a Custom Page in OpenCart 3 (viewtopic.php?f=23&t=186404)
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 {
private $error = array();
public function index() {
$this->language->load('information/static'); //Optional. This calls for your language file
$this->document->setTitle($this->language->get('heading_title')); //Optional. Set the title of your web 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')
);
$data['heading_title'] = $this->language->get('heading_title'); //Get "heading title" from language file.
$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');
// OpenCart 2.1 and below CHOOSE ACCORDINGLY
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/static.tpl')) { //if file exists in your current template folder
$this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/information/static.tpl', $data)); //get it
} else {
$this->response->setOutput($this->load->view('default/template/information/static.tpl', $data)); //or get the file from the default folder
}
// OpenCart 2.2 and above CHOOSE ACCORDINGLY
$this->response->setOutput($this->load->view('information/information', $data));
}
}
Create a file name 'static.tpl' in /catalog/view/theme/default/template/information/
Code: Select all
<?php echo $header; ?>
<div class="container">
<ul class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
<?php } ?>
</ul>
<div class="row"><?php echo $column_left; ?>
<?php if ($column_left && $column_right) { ?>
<?php $class = 'col-sm-6'; ?>
<?php } elseif ($column_left || $column_right) { ?>
<?php $class = 'col-sm-9'; ?>
<?php } else { ?>
<?php $class = 'col-sm-12'; ?>
<?php } ?>
<div id="content" class="<?php echo $class; ?>"><?php echo $content_top; ?>
<h1><?php echo $heading_title; ?></h1>
YOUR OWN CONTENTS
<?php echo $content_bottom; ?></div>
<?php echo $column_right; ?></div>
</div>
<?php echo $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