Creating a Custom Page in OpenCart - part 1
Written by MarketInSG in Tutorials on July 21, 2012 | 60 Comments
“How do I create an additional page in my OpenCart website?” That’s likely the question that brought you here. So, here is a simple tutorial for you to begin with. I will assume you already have basic PHP knowledge and HTML knowledge. If you don’t, not to worry, you can read the comments beside each line to help you understand.
Understanding OpenCart
OpenCart uses a MVC + (L) framework. So basically, you will need a few compulsory files created for it to work.
Required files:
- A controller file
- A template file
Optional files:
- Model file
- Language file
Controller File
You will need to first create a controller file in the controller folder. For this tutorial, I will create a file named ‘static.php’ in the /catalog/controller/information/ folder. Since we named the file static.php and put it at information/ folder, the controller class name will be ControllerInformationStatic.
<?php class ControllerInformationStatic extends Controller { 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. $this->data['breadcrumbs'] = array(); $this->data['breadcrumbs'][] = array( 'text' => $this->language->get('text_home'), 'href' => $this->url->link('common/home'), 'separator' => false ); $this->data['breadcrumbs'][] = array( 'text' => $this->language->get('heading_title'), 'href' => $this->url->link('information/static'), 'separator' => $this->language->get('text_separator') ); // Text from language file $this->data['heading_title'] = $this->language->get('heading_title'); //Get "heading title" $this->data['text_content'] = $this->language->get('text_content'); // We call this Fallback system if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/static.tpl')) { //if file exists in your current template folder $this->template = $this->config->get('config_template') . '/template/information/static.tpl'; //get it } else { $this->template = 'default/template/information/static.tpl'; //or get the file from the default folder } //Required. The children files for the page. $this->children = array( 'common/column_left', 'common/column_right', 'common/content_top', 'common/content_bottom', 'common/footer', 'common/header' ); $this->response->setOutput($this->render()); } } ?>
So let me explain what’s being done above. In a MVC framework, the controller file is loaded. It is literally the brain of the whole page. It processes and do according to what you asked it to. So “$this->template = $this->config->get(‘config_template’) . ‘/template/information/static.tpl’;” is asking to load for your template file, which will lead us to the next part.
Template File
So, this is one of the required files too. We will create a file named ‘static.tpl’ in the /catalog/view/theme/default/template/information/ folder.
<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?> <div id="content"> <?php echo $content_top; ?> <div class="breadcrumb"> <?php foreach ($breadcrumbs as $breadcrumb) { ?> <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a> <?php } ?> </div> <h1><?php echo $heading_title; ?></h1> <?php echo $text_content; ?> <?php echo $content_bottom; ?> </div> <?php echo $footer; ?>
So what basically happens above is that it is loading all the things you will see in your browser. It will load your header and footer, which will get the layout of your website. Nothing fancy about it, all your styling is done here. So, you will wonder about those optional files I mentioned, which will bring us to the next part of the tutorial.
Language File
As most of you know, OpenCart supports multi-language. You can have multiple language file in your language folder so that it can be loaded in different language. However, for this tutorial, we will be creating only for the English language. We will start with creating a file named ‘static.php’ in the catalog/language/english/information/ folder.
<?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 // Text $_['text_content'] = 'My Static Page Content'; ?>
Wondering what the magical line of code above does? Well, it is what the line of code “ $this->data['heading_title'] = $this->language->get(‘heading_title’);” in your controller file is calling for. Without this line, your controller file will not be able to get the words you would like to display.
You can download all files from this tutorial in file below:
So basically, you have successfully made your custom page. You can now access the page you created from yourwebsite.com/index.php?route=information/static. Easy as it seems, but you can surely do more with these simple little things, which we will cover in the second part of the tutorial. The second part of the tutorial will cover on using the model files and search engine optimization.
60 Comments on "Creating a Custom Page in OpenCart - part 1"
I amm really excited by the fixsed coronary heart
fee monitoring without a chest strap.
Here iis my homepage: cara belajar bahasa inggris otodidak
Like default slider in the home page i have to add another one more slider in the home page just under the default slider. How can I do that?
In fact, the most difficᥙlt pɑrt of
thе procеѕs iѕ Ԁiаɡnoѕіng
tһе ρгοЬlеm
aѕ a ᏒАӍ faіlurᥱ.
Wе ɑre thᥱ Ьеѕt in ⅼaрtор аnd
ρc гᥱⲣaіг
in ᒪօndоn beϲɑuѕᥱ
աе Ьelіеѵе іn 100% ϲuѕtⲟmег ѕatіѕfаϲtіⲟn. Ⅰf yоս Ԁⲟn’t қnoա tɦеm, ρut thеm in tҺᥱ Ƅuⅼҝ еmaіⅼ ρilᥱ ɑnd tҺen “choose” tο alⅼоw thᥱm іntߋ уоᥙr сiгсlᥱ.
Ӏt іѕ bеѕt to ѕеe an Ꭺtⅼantɑ ⅼaρtοр reрaіr ѕρеcіɑlіѕt.
The Ьᥱѕt tеchniԛսe tо tгοսblesɦⲟοt ѵігuѕ іѕѕսеѕ оf tɦе cοmⲣuteг іѕ оnlіne ϲⲟmpᥙtᥱг ѕᥙрpоrt ѕеrνіϲe ρгⲟѵіԀеd tҺrߋսցһ mսltірⅼe ϲhannеls.
Ⅿү Ьlօɡ pоѕt ::
Dr.IT Services - data recovery software
I really don’t know what it was, but every
time I caught someone looking the other way or I’d come up behind them, they’d
spin and it’d be a head shot. Now might not be a good idea
to disturb them because they might end up growling at you in frustration. This gives it an edge over many other strategy games which also work well on a netbook.
is it possible to include an another php file with this static files ? and how can i do it ?
i need to add UberGallery script in my opencart store as a image gallery, but im not understand this MVC system
As a store honer I want to make a seller information page on which I want to put some link related to video (like packaging, product upload etc ). When a vendor/seller click that link, video start to download. Is it possible with OpenCart? I have no knowledge about PHP, JavaScript, CSS or other.
plz help me. If above possible plz sent me the way, on my email address.
Hello Harbindra,
Yes it’s possible but i need to deeply understand your requirement so explain properly what do you want.
Oh my goodness! Impressive article dude!
Thank you so much, However I am experiencing problems with your RSS.
I don’t know the reason why I am unable to join it.
Is there anybody else having similar RSS issues? Anybody who knows the answer can you kindly respond?
Thanks!!
Hello,
I am trying to create a custom pages as per your code presented, but getting error, i am using opencart v2.0.1.1 , pls. help.
I’m getting this error on the latest opencart
Notice: Indirect modification of overloaded property ControllerInformationStatic::$data has no effect in /var/www/html/upload2/catalog/controller/information/static.php on line 8Notice: Indirect modification of overloaded property ControllerInformationStatic::$data has no effect in /var/www/html/upload2/catalog/controller/information/static.php on line 9Notice: Indirect modification of overloaded property ControllerInformationStatic::$data has no effect in /var/www/html/upload2/catalog/controller/information/static.php on line 14Notice: Indirect modification of overloaded property ControllerInformationStatic::$data has no effect in /var/www/html/upload2/catalog/controller/information/static.php on line 21Notice: Indirect modification of overloaded property ControllerInformationStatic::$data has no effect in /var/www/html/upload2/catalog/controller/information/static.php on line 22
the same problem for my. Can sombody help??
replace “$this->data” with “$data”
Good day! This post couldn’t be written any better!
Reading this post reminds me of my good old room
mate! He always kept talking about this. I will
forward this page to him. Pretty sure he will have a good read.
Many thanks for sharing!
Good article. I’m facing some of these issues as well..
My co-worker recommended this site from a post he read the other day. I’m glad he did! Thanks!
Hey author
Amazing read. Thanks a ton. It’s difficult to find a good read for opencart like this one.
For beginners like me it was a road map.
Looking forward for more such basics. Also you can take detailed example on common requests. Thanks again
When someone writes an article he/she keeps the plan of a user in his/her brain that how a user can know it.
So that’s why this article is outstdanding. Thanks!
I think this is one of the most significant information for me.
And i’m glad reading your article. But want to remark
on some general things, The site style is ideal,
the articles is really excellent : D. Good job, cheers
Good info. Lucky me I discovered your website by accident (stumbleupon).
I have book marked it for later!
very nice tutorial
Plese suggest me how to create page in opencart front in accout folder.
Hi
thank you for this very interesting topic, actually I want to create a page like this but in account page, I mean such as the pages that customer needs to log in before can access to it.
any help?
hi. does anyone know how to create custom layouts for o.c 1.5.4.1. i want to add unique banners to particular unique subcategories. but need to create custom layouts for those particular subcategory pages. can anyone assist with that? thank you
I always spent my half an hour to read this web site’s
articles daily along with a mug of coffee.
Thank you! Easy to install and it’s working on Opencart v1.5.6.1
thanks for this tutorials. got it!
btw, i am a newbie in opencart and posting this sh*t here helps me a lot. Cool!
thanks its working.. but still m unable to fully understand how the codes of opencart
Thanks for your help man. Just a bug. Everything is working fine in opencart 1.5.5.1 there is just the problem that when you access the static page I uploaded and my custom page I got the $column_left code under my menu. You can see it accessing http://afeto.mongesdatrindade.org.br/index.php?route=information/grife
Can you help me to fix it?
Does this work on Opencart 1.5.6 ?
I gotta two questions running in my mind.
1. is it possible to make only controller file that pass data on the theme/default/common/header.tpl
2. Lets say I created a dynamic css named stylesheet.php in the catalog\view\theme\theme_name\stylesheet\
So I wanna know,
is it possible to pass the array of value from any controller file to stylesheet.php ??
help me through this I was searching for these answers so long. Any help should be appreciate.
I’m getting an error:
Notice: Error: Could not load template /home/layercak/public_html/layercake-store/catalog/view/theme/default/template/information/thankyou.tpl! in /home/layercak/public_html/layercake-store/vqmod/vqcache/vq2-system_engine_controller.php on line 76
Am I missing some additional steps?
where is admin ?
You wont need admin panel. Just go to System > Design > Layout and design a layout and assign this address to it information/static. Now you can display any module on that layout in content top, content bottom, column left and column right. Awesome tutorial.. totally worked for me on 1.5.5.1
Can i call on specific categories on footer using php not a custom ..
Its not working on opencart 1.5.5.1 please help!
dilip@ebonyte.com
Does this tutorial work in OC 1.5.5.1? I tried several times but it doesn’t seems to work.
Hello
I want to thank you for this great and easy tuto.
Just one thing I downloaded the files but couldn’t extract them because they are password protect.
So I had to create my own files but it’s working perfectly.
Thanks
Cleo
THANKS FOR THIS BEAUTIFUL, NICE & EASY TUTORIAL…. GREAT!!!
Hi!
Got it a few minutes ago and works wonders, thanks!!
I was wondering how I could have this new page show a different header than the rest of the pages? I want this page not to show the shpping cart for instance, and not to show either the categories menu: in fact, I need this page to be my welcome page, and as such not show anything oriented to selling but for a link called “Go to the online shop” in the header menu; the rest would be only information about my products…
Thanks!
you can do so easily by remove and replace it with your own design there
Hello,
I don’t know how do I link this page to my menu bar
The result looks like this http://sanolife.ro/index.php?route=information/static
but how I access this link prom my page directly just like I access the home page?
Thank you
just add a link to your footer or something will do
Can you be more specific please?
I want that page to show up in the menu bar where the categories are. What should I do for that?
Thanks.
in catalog/view/theme/*/template/common/header.tpl find and modify from there. it depends on your theme.
Thanks. I’ll try to find what I should modify. My theme is the default theme just with a background and some different colors.
I believe somewhere in this part of the code I must insert the link for the static page.
<a href="”>
<?php for ($i = 0; $i
<?php for (; $i
<a href="”>
Done.
Thanks for the help.:D
I have made the same thing that you have posted. You can see the link here: http://www.kem-parts.com/DROMEAS/new/site1/store/index.php?route=information/staticnew
I don’t know why i experience this problem if you need something else please send me a message.
As you can see i am using Basico theme…..
Hey,
I have a problem with my custom pages!! I cannot see the quantity at the cart…… Please help me i think there is a problem in the controller file…
Thanks
That depends on how you coded it. maybe you can show how you coded?
How can I add things to column right for example (I’d like to have categories shown), on a custom page like this one?
Thanks!
You will have to add additional layout. You can add layout from admin panel system > design > layout
Of course!
Thanks again!
where is the second part?
It’s getting reviewed.
It’s out now at https://androidappdictions.com/tutorials/creating-a-custom-page-in-opencart-part-2/
Part 2 will be out in a week! Stay tune!
Soon, no worries
wend it second part?
Trackbacks for this post