Post by MarketInSG » Fri Aug 04, 2017 11:03 pm

Other tutorials:
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));
	}
}
Template file

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 }}
Language file

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';
This should help those that are just getting started with OpenCart. Any questions, feel free to ask :)


User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by riwalker » Tue Dec 12, 2017 4:17 am

and once uploaded to the prescribed folders, how do you load this as a new module ? (I don't see the module 'static' once uploaded)

Newbie

Posts

Joined
Thu Nov 23, 2017 9:46 pm

Post by cyclops12 » Wed Dec 13, 2017 4:15 am

riwalker wrote:
Tue Dec 12, 2017 4:17 am
and once uploaded to the prescribed folders, how do you load this as a new module ? (I don't see the module 'static' once uploaded)
This is to create a custom page...not a module.

Active Member

Posts

Joined
Sun Sep 27, 2015 1:10 am

Post by bronts » Sun May 27, 2018 5:57 am

Hi, and thank you for your tutorial.
I need to create 2 new custom pages.
Please see: http://www.redraglyn.com/
I have already (with help) created html content in the left sidebar section and the list is in and ready to go (last link will be a .pdf so no new page needed for it).
I presume your wording 'static' is the name of (or describes) the new page you made and therefore I will need to rename mine to something more suitable ie: 'silver_care'?
And do I have to create all those pages x 2 for the 2 new pages I need?

Thank you
Brontè

User avatar
Active Member
Online

Posts

Joined
Sat Jul 14, 2012 12:56 pm
Location - QLD Australia

Post by bronts » Sun Jun 03, 2018 6:06 pm

As I didn't get a reply and I wasn't sure, I have just added new pages in the information section of admin, made sort order 0 so they don't come up in the information section in the footer and just linked to them in my new jewellery section on the left.
It obviously wont list correctly in the sitemap page but it's a quick fix and it worked.

User avatar
Active Member
Online

Posts

Joined
Sat Jul 14, 2012 12:56 pm
Location - QLD Australia

Post by MarketInSG » Mon Jun 04, 2018 2:26 pm

bronts wrote:
Sun May 27, 2018 5:57 am
Hi, and thank you for your tutorial.
I need to create 2 new custom pages.
Please see: http://www.redraglyn.com/
I have already (with help) created html content in the left sidebar section and the list is in and ready to go (last link will be a .pdf so no new page needed for it).
I presume your wording 'static' is the name of (or describes) the new page you made and therefore I will need to rename mine to something more suitable ie: 'silver_care'?
And do I have to create all those pages x 2 for the 2 new pages I need?

Thank you
Brontè
That's correct, just duplicate the files and rename "static" to something else you need will do.


User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by bronts » Sun Jun 10, 2018 11:04 am

thank you.
I appreciate your reply.
This forum is such a wealth of knowledge and I am learning a lot from it's members.

User avatar
Active Member
Online

Posts

Joined
Sat Jul 14, 2012 12:56 pm
Location - QLD Australia
Who is online

Users browsing this forum: No registered users and 16 guests