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.

Expert 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

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

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

Posts

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

Post by rene.reetz » Tue Jan 08, 2019 4:04 am

how to add seo-url to the created page?

Newbie

Posts

Joined
Tue Jan 08, 2019 4:04 am

User avatar
Guru Member

Posts

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

Post by jakenjilyt » Mon Mar 18, 2019 5:04 pm

If this is not to make a module how do you access this page? thanks

Newbie

Posts

Joined
Fri Mar 15, 2019 8:30 am

Post by mrvogl@gmail.com » Wed Apr 10, 2019 6:31 am

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


Posts

Joined
Wed Apr 10, 2019 4:54 am

Post by wywong » Thu Apr 11, 2019 6:10 pm

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

Newbie

Posts

Joined
Fri Mar 29, 2019 10:02 am

Post by tantadruj » Wed Feb 05, 2020 5:15 pm

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?
Last edited by straightlight on Wed Feb 05, 2020 9:44 pm, edited 1 time in total.
Reason: Added code tags.

New member

Posts

Joined
Fri Jun 23, 2017 12:40 pm

Post by tantadruj » 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.

New member

Posts

Joined
Fri Jun 23, 2017 12:40 pm

Post by straightlight » Wed Feb 05, 2020 9:45 pm

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.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by SynysterDory » 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)

New member

Posts

Joined
Fri Nov 22, 2019 3:52 am
Location - México

Post by straightlight » Thu Mar 05, 2020 4:07 am

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.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by SynysterDory » 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

New member

Posts

Joined
Fri Nov 22, 2019 3:52 am
Location - México

Post by straightlight » Fri Mar 06, 2020 12:09 am

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?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by SynysterDory » Fri Mar 06, 2020 12:42 am

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

New member

Posts

Joined
Fri Nov 22, 2019 3:52 am
Location - México
Who is online

Users browsing this forum: No registered users and 17 guests