Page 1 of 2

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

Re: Creating a Custom Page in OpenCart 3

Posted: Wed Feb 05, 2020 5:15 pm
by tantadruj
Hello,
your page "static" works perfectly. But if I make another one and change its name to "static1" or "store" it gives me an error:

Code: Select all

Fatal error: Uncaught Error: Class 'Controllerinformationstatic1' not found in C: \ xampp \ storage \ modification \ system \ engine \ action.php: 71 Stack trace: # 0 C: \ xampp \ htdocs \ OPENCART \ catalog \ controller \ startup \ router.php (25): Action-> execute (Object (Registry)) # 1 C: \ xampp \ storage \ modification \ system \ engine \ action.php (79): ControllerStartupRouter-> index () # 2 C: \ xampp \ htdocs \ OPENCART \ system \ engine \ router.php (67): Action-> execute (Object (Registry)) # 3 C: \ xampp \ htdocs \ OPENCART \ system \ engine \ router.php (56): Router-> execute (Object (Action)) # 4 C: \ xampp \ htdocs \ OPENCART \ system \ framework.php (165): Router-> dispatch (Object (Action), Object (Action)) # 5 C: \ xampp \ htdocs \ OPENCART \ system \ startup.php (104): require_once ('C: \\ xampp \\ htdocs ...') # 6 C: \ xampp \ htdocs \ OPENCART \ index.php (19): start ('catalog') # 7 {main} thrown in C: \ xampp \ storage \ modification \ system \ engine \ action.php on line 71
can you help me please?

Re: Creating a Custom Page in OpenCart 3

Posted: Wed Feb 05, 2020 7:50 pm
by tantadruj
ok. I did. i added all the new pages via information (dashboard/catalog/information) without check the bottom tag and of course the order status, this must be checked only if you want the page display in info column-the first from left) and then made a link to them in the footer. File to modificate is:

catalog/controller/common/footer.php (copy one line and change with your lik name and route (you see this in browser when create the page)
catalog/view/theme/your theme/template/common/footer.twig (add link, copy one line and change with your link name )
catalog/language/your language/common/footer.php (copy one line and change to your link, the right side is what you will see as a link in frontend)

Hope this helps anyone else.

Re: Creating a Custom Page in OpenCart 3

Posted: Wed Feb 05, 2020 9:45 pm
by straightlight
tantadruj wrote:
Wed Feb 05, 2020 7:50 pm
ok. I did. i added all the new pages via information (dashboard/catalog/information) without check the bottom tag and of course the order status, this must be checked only if you want the page display in info column-the first from left) and then made a link to them in the footer. File to modificate is:

catalog/controller/common/footer.php (copy one line and change with your lik name and route (you see this in browser when create the page)
catalog/view/theme/your theme/template/common/footer.twig (add link, copy one line and change with your link name )
catalog/language/your language/common/footer.php (copy one line and change to your link, the right side is what you will see as a link in frontend)

Hope this helps anyone else.
Better to use a module or extension to modify controller files originating from the core.

Re: Creating a Custom Page in OpenCart 3

Posted: Thu Mar 05, 2020 3:56 am
by SynysterDory
How can I place a image to that twig file? I don't know how since it's not an "html base twig file" (that's how I 'stand twig files)

Re: Creating a Custom Page in OpenCart 3

Posted: Thu Mar 05, 2020 4:07 am
by straightlight
SynysterDory wrote:
Thu Mar 05, 2020 3:56 am
How can I place a image to that twig file? I don't know how since it's not an "html base twig file" (that's how I 'stand twig files)
TWIG files are still pure HTML codes. It's just that, unless using an extension, you won't be able to use PHP codes inside of them by default. As far as adding image codes, it's pretty much the same as adding an IMG SRC into an HTML file.

Re: Creating a Custom Page in OpenCart 3

Posted: Thu Mar 05, 2020 11:34 pm
by SynysterDory
straightlight wrote:
Thu Mar 05, 2020 4:07 am
TWIG files are still pure HTML codes. It's just that, unless using an extension, you won't be able to use PHP codes inside of them by default. As far as adding image codes, it's pretty much the same as adding an IMG SRC into an HTML file.
Got it!
I achieved it in my local host, but not in the online one

Code: Select all

<a href="https://mysite.com/image/catalog/it_process.png" title="Process" <img src="https://mysite.com/image/catalog/it_process.png" alt="Process" width="800" height="618"/>
I cleaned the cache in the admin panel and in server, but the image doesn't show

Re: Creating a Custom Page in OpenCart 3

Posted: Fri Mar 06, 2020 12:09 am
by straightlight
SynysterDory wrote:
Thu Mar 05, 2020 11:34 pm
straightlight wrote:
Thu Mar 05, 2020 4:07 am
TWIG files are still pure HTML codes. It's just that, unless using an extension, you won't be able to use PHP codes inside of them by default. As far as adding image codes, it's pretty much the same as adding an IMG SRC into an HTML file.
Got it!
I achieved it in my local host, but not in the online one

Code: Select all

<a href="https://mysite.com/image/catalog/it_process.png" title="Process" <img src="https://mysite.com/image/catalog/it_process.png" alt="Process" width="800" height="618"/>
I cleaned the cache in the admin panel and in server, but the image doesn't show
Ensure your image path and image name both exists and that the domain and image path in both config.php files are properly configured.
I cleaned the cache in the admin panel and in server, but the image doesn't show
What is the way you used to clean the cache?

Re: Creating a Custom Page in OpenCart 3

Posted: Fri Mar 06, 2020 12:42 am
by SynysterDory
straightlight wrote:
Fri Mar 06, 2020 12:09 am
Ensure your image path and image name both exists and that the domain and image path in both config.php files are properly configured.
I cleaned the cache in the admin panel and in server, but the image doesn't show
What is the way you used to clean the cache?
Everything in its place. I've erased the reference and problem have been solved

Since I only have access to the server through an FTP client, my supervisor's who clean the cache.
After upload changes:
1. In admin panel with the blue gear icon top-right
2. Open a new browser, clean cache and press 3 times ctrl+f5