Page 1 of 1

Creating a Custom Page in OpenCart 3

Posted: Fri Aug 04, 2017 11:03 pm
by MarketInSG
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 :)

Re: Creating a Custom Page in OpenCart 3

Posted: Tue Dec 12, 2017 4:17 am
by riwalker
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)

Re: Creating a Custom Page in OpenCart 3

Posted: Wed Dec 13, 2017 4:15 am
by cyclops12
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.

Re: Creating a Custom Page in OpenCart 3

Posted: Sun May 27, 2018 5:57 am
by bronts
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è

Re: Creating a Custom Page in OpenCart 3

Posted: Sun Jun 03, 2018 6:06 pm
by bronts
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.

Re: Creating a Custom Page in OpenCart 3

Posted: Mon Jun 04, 2018 2:26 pm
by MarketInSG
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.

Re: Creating a Custom Page in OpenCart 3

Posted: Sun Jun 10, 2018 11:04 am
by bronts
thank you.
I appreciate your reply.
This forum is such a wealth of knowledge and I am learning a lot from it's members.

Re: Creating a Custom Page in OpenCart 3

Posted: Tue Jan 08, 2019 4:04 am
by rene.reetz
how to add seo-url to the created page?

Re: Creating a Custom Page in OpenCart 3

Posted: Wed Jan 16, 2019 6:57 pm
by MarketInSG
You can add a htaccess rewrite for the URL

Re: Creating a Custom Page in OpenCart 3

Posted: Mon Mar 18, 2019 5:04 pm
by jakenjilyt
If this is not to make a module how do you access this page? thanks

Re: Creating a Custom Page in OpenCart 3

Posted: Wed Apr 10, 2019 6:31 am
by mrvogl@gmail.com
jakenjilyt wrote:
Mon Mar 18, 2019 5:04 pm
If this is not to make a module how do you access this page? thanks
I'd like to know this too? I'm new to opencart and twig. I see the "page" in the information template, but I don't know how to make this page display on my website. Guess I need to watch some beginner videos on how all this works

Re: Creating a Custom Page in OpenCart 3

Posted: Thu Apr 11, 2019 6:10 pm
by wywong
You may amend the url to access
"http://example.com/index.php?route=information/static"

replace the link after "route=" to your custom page name