Creating a Custom Page in OpenCart – part 1

Written by in Tutorials on July 21, 2012  |  48 Comments

creating-a-custom-page-in-opencart-part-1

“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:

  1. A controller file
  2. A template file

Optional files:

  1. Model file
  2. 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:

Download3399 downloads

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.

Tags: , , ,

About the Author

Joined OpenCart community since November 2011. MarketInSG is Singapore's first website dedicated to OpenCart web designing & modification.

View all posts by

48 Comments on "Creating a Custom Page in OpenCart – part 1"

  1. purchase twitter followers July 29, 2014 at 1:10 am · Reply

    We stumbled over here by a different page and thought
    I should check things out. I like what I see so
    now i’m following you. Look forward to looking at your web page again.

  2. Raymon July 27, 2014 at 9:16 pm · Reply

    I tend not to comment, but I looked at some of the remarks on Creating a Custom Page in OpenCart – part 1. I do have a few questions for you if it’s allright. Could it be only me or does it look like some of the remarks look like they are left by brain dead people? :-P And, if you are posting on other sites, I would like to follow you. Could you post a list of every one of your social networking pages like your twitter feed, Facebook page or linkedin profile?

  3. parth June 15, 2014 at 5:23 am · Reply

    very nice tutorial
    Plese suggest me how to create page in opencart front in accout folder.

  4. behghool June 9, 2014 at 5:59 pm · Reply

    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?

  5. tree climbing spikes May 14, 2014 at 4:14 am · Reply

    always i used to read smaller articles or reviews that
    also clear their motive, and that is also happening with this
    paragraph which I am reading at this place.

  6. Cortez May 9, 2014 at 3:47 pm · Reply

    I’ve been surfing online more than 4 hours today, yet I never found any interesting article like yours.
    It’s pretty worth enough for me. Personally, if all website owners and bloggers made good content as
    you did, the internet will be much more useful than ever before.|
    I could not resist commenting. Well written!|
    I will immediately clutch your rss as I can not find your e-mail subscription hyperlink or newsletter service.
    Do you’ve any? Please permit me understand so that I may just
    subscribe. Thanks.|
    It is the best time to make some plans for the future
    and it’s time to be happy. I’ve read this post and if I could I desire to suggest you few interesting things or advice.

    Maybe you can write next articles referring to this article.
    I wish to read even more things about it!|
    It is the best time to make a few plans for the longer term and it’s time to be happy.

    I have read this publish and if I may I want to recommend
    you some interesting things or tips. Maybe you can write subsequent articles relating to this article.
    I want to read more things approximately it!|
    I’ve been browsing on-line more than 3 hours lately, but I never found any fascinating article like yours.
    It’s pretty worth enough for me. In my opinion, if all website owners and bloggers made just right content
    as you did, the web shall be much more useful than ever before.|
    Ahaa, its nice conversation about this paragraph here at this blog, I have read all that, so
    now me also commenting at this place.|
    I am sure this article has touched all the internet users, its really really fastidious piece
    of writing on building up new website.|
    Wow, this paragraph is fastidious, my sister is analyzing these kinds of things,
    therefore I am going to inform her.|
    bookmarked!!, I really like your web site!|
    Way cool! Some extremely valid points! I appreciate you writing
    this post and the rest of the site is also really good.|
    Hi, I do think this is an excellent website. I stumbledupon it ;) I’m going to revisit once again since i have book-marked it.
    Money and freedom is the best way to change, may you be rich and
    continue to guide others.|
    Woah! I’m really digging the template/theme of this blog.
    It’s simple, yet effective. A lot of times it’s tough to get that “perfect balance” between usability and visual appeal.

    I must say you have done a very good job with this.
    Additionally, the blog loads super fast for me
    on Firefox. Excellent Blog!|
    These are truly impressive ideas in about blogging.
    You have touched some good things here. Any way keep up wrinting.|
    Everyone loves what you guys tend to be up too.
    Such clever work and reporting! Keep up the superb works guys I’ve included you guys to blogroll.|
    Hello! Someone in my Facebook group shared this
    site with us so I came to give it a look. I’m definitely
    enjoying the information. I’m bookmarking and will be tweeting this to my followers!
    Outstanding blog and fantastic style and design.|
    I like what you guys are usually up too. This type of clever work and coverage!
    Keep up the superb works guys I’ve incorporated you guys to my own blogroll.|
    Howdy would you mind stating which blog platform you’re using?

    I’m looking to start my own blog soon but I’m having a hard
    time selecting between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your layout seems different then most blogs and I’m looking for
    something unique. P.S My apologies for being off-topic but I had to ask!|
    Hi would you mind letting me know which web host you’re working with?
    I’ve loaded your blog in 3 different web browsers and I must say this blog loads a lot quicker then most.
    Can you suggest a good internet hosting provider at a reasonable price?
    Kudos, I appreciate it!|
    I love it whenever people come together and share views.
    Great website, continue the good work!|
    Thank you for the good writeup. It in fact was a amusement account it.
    Look advanced to far added agreeable from you! By the way,
    how can we communicate?|
    Hello just wanted to give you a quick heads up. The words in your content seem to
    be running off the screen in Opera. I’m not sure if this is a formatting issue or something to
    do with internet browser compatibility but I figured I’d post to let you know.
    The style and design look great though! Hope you get the problem
    solved soon. Thanks|
    This is a topic that is close to my heart… Thank you!

    Exactly where are your contact details though?|
    It’s very effortless to find out any matter on net as compared to books, as I found this post at this site.|
    Does your blog have a contact page? I’m having a tough time locating it but, I’d like to send you an
    e-mail. I’ve got some creative ideas for your blog you
    might be interested in hearing. Either way, great website and I look forward to seeing it develop over time.|
    Greetings! I’ve been reading your weblog for some time now and
    finally got the courage to go ahead and give you a shout out from Humble Tx!
    Just wanted to mention keep up the excellent work!|
    Greetings from Los angeles! I’m bored at work so I decided to check out your blog on my iphone during lunch break.

    I enjoy the info you present here and can’t wait
    to take a look when I get home. I’m surprised at how quick your blog loaded on my phone ..

    I’m not even using WIFI, just 3G .. Anyways, wonderful site!|
    Its such as you learn my mind! You seem to grasp a lot approximately this, like you wrote the e-book
    in it or something. I feel that you could do with a few %
    to pressure the message house a bit, but other than that, this is fantastic
    blog. An excellent read. I’ll certainly be back.|
    I visited multiple blogs however the audio feature for audio
    songs present at this site is really fabulous.|
    Hi, i read your blog from time to time and i own a similar one and i was just wondering if you get a lot of spam remarks?
    If so how do you prevent it, any plugin or anything you can suggest?

    I get so much lately it’s driving me crazy so any assistance is very much appreciated.|
    Greetings! Very useful advice within this article! It is the
    little changes which will make the largest changes.
    Many thanks for sharing!|
    I seriously love your website.. Excellent colors & theme.
    Did you build this site yourself? Please reply back as I’m planning to create my own
    site and would like to learn where you got this from or exactly what the
    theme is named. Kudos!|
    Howdy! This post could not be written any better!
    Looking at this article reminds me of my previous roommate!
    He always kept talking about this. I will send this information to
    him. Pretty sure he will have a good read.
    Many thanks for sharing!|
    Whoa! This blog looks exactly like my old one!
    It’s on a entirely different topic but it has pretty much the same layout and design.
    Superb choice of colors!|
    There’s certainly a lot to find out about this issue.
    I like all of the points you’ve made.|
    You’ve made some good points there. I checked on the web to learn more about the issue and found most individuals will go along with
    your views on this site.|
    Hi, I check your blog on a regular basis. Your story-telling style is witty,
    keep it up!|
    I just couldn’t go away your website prior to suggesting that I extremely loved the standard info a person supply in your guests?
    Is gonna be again steadily to inspect new posts|
    I want to to thank you for this excellent read!! I absolutely loved every little bit of it.
    I have you saved as a favorite to look at new things you post…|
    Hi there, just wanted to say, I liked this blog post. It was helpful.

    Keep on posting!|
    I create a comment when I appreciate a post on a
    website or I have something to add to the discussion.
    It is a result of the fire displayed in the article I read.
    And after this article Creating a Custom Page in OpenCart – part 1
    - OpencartNews. I was actually excited enough to write a thought ;) I do have 2 questions for
    you if it’s okay. Is it just me or do a few of the comments come across like they are
    written by brain dead folks? :-P And, if you are posting at other sites, I would like to follow everything new you have to post.
    Could you make a list the complete urls of all your social
    sites like your twitter feed, Facebook page or linkedin profile?|
    Hello, I enjoy reading through your post. I like to write a little comment to support you.|
    I every time spent my half an hour to read this website’s articles every day along with a
    mug of coffee.|
    I all the time emailed this web site post page to all my associates, as if like to
    read it then my friends will too.|
    My developer is trying to convince me to move to .net from PHP.

    I have always disliked the idea because of the expenses.

    But he’s tryiong none the less. I’ve been using Movable-type on a
    variety of websites for about a year and am anxious about switching to another platform.
    I have heard good things about blogengine.net.
    Is there a way I can transfer all my wordpress content into it?
    Any kind of help would be really appreciated!|
    Hi there! I could have sworn I’ve visited your blog before but after browsing through some of the posts I realized it’s new to me.
    Regardless, I’m definitely delighted I discovered it and
    I’ll be book-marking it and checking back regularly!|
    Terrific work! This is the kind of info that are meant to be shared across the internet.
    Disgrace on Google for now not positioning this post higher!
    Come on over and seek advice from my site .
    Thanks =)|
    Heya i am for the first time here. I came across this board and I find It truly useful & it helped me out
    much. I hope to give something back and aid others like you aided me.|
    Hi, I do think your site could be having browser compatibility issues.

    When I look at your blog in Safari, it looks fine however, when opening in I.E., it has some overlapping issues.
    I just wanted to give you a quick heads up! Aside from
    that, wonderful blog!|
    A person essentially help to make significantly posts I would state.
    This is the first time I frequented your web page and so far?
    I amazed with the analysis you made to create this particular submit extraordinary.
    Magnificent activity!|
    Heya i’m for the first time here. I came across this board and I
    to find It really helpful & it helped me out a lot.
    I am hoping to offer one thing back and aid others such
    as you aided me.|
    Howdy! I simply wish to offer you a huge thumbs up for the excellent info you’ve got right
    here on this post. I am returning to your blog for more soon.|
    I every time used to read piece of writing in news papers but now as I am a
    user of web therefore from now I am using net for posts, thanks to web.|
    Your way of explaining all in this piece of writing
    is in fact nice, every one be able to without difficulty know it, Thanks a lot.|
    Hi there, I discovered your site by way of Google at the same time as searching for
    a comparable subject, your site came up, it seems to
    be great. I’ve bookmarked it in my google bookmarks.

    Hello there, simply was alert to your weblog via Google, and
    found that it is really informative. I am gonna watch out for brussels.
    I’ll be grateful if you continue this in future.
    A lot of other folks will likely be benefited from your writing.
    Cheers!|
    I am curious to find out what blog system you’re using?
    I’m experiencing some small security issues with my latest website and I’d like to find
    something more secure. Do you have any recommendations?|
    I’m extremely impressed with your writing skills
    and also with the layout on your weblog. Is this a paid theme or did you customize it yourself?
    Either way keep up the excellent quality
    writing, it is rare to see a nice blog like this one nowadays.|
    I am extremely inspired along with your writing abilities and also
    with the layout in your weblog. Is that this a paid theme or
    did you modify it yourself? Either way stay up the nice
    high quality writing, it’s uncommon to peer a nice blog like this one nowadays..|
    Hi, Neat post. There is an issue together with your site
    in internet explorer, may check this? IE nonetheless
    is the market leader and a good section of folks will pass over your great writing because of this problem.|
    I’m not sure where you’re getting your information, but good topic.
    I needs to spend some time learning more or understanding more.
    Thanks for great information I was looking for this
    information for my mission.|
    Hello, i think that i saw you visited my weblog thus i came to “return the favor”.I am
    trying to find things to enhance my site!I suppose its ok to use {some of|a fe
    \

  7. how to speed up pc May 7, 2014 at 9:37 pm · Reply

    Starting with the basics, the Cisco network is traditionally defined
    as a three-tier hierarchical model comprising the
    core, distribution, and access layers. You may uninstall few unwanted programs or attach an extra HDD.
    These automatic updates are commonplace, and they can slow down your system and can make internet browsing slower as
    well.

  8. sell my car broward May 6, 2014 at 11:50 pm · Reply

    Good day! Do you know if they make any plugins to safeguard against hackers?
    I’m kinda paranoid about losing everything I’ve worked
    hard on. Any tips?

  9. neddy April 23, 2014 at 2:19 pm · Reply

    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

  10. dumpsterrentals.pen.io April 18, 2014 at 9:14 pm · Reply

    I always spent my half an hour to read this web site’s
    articles daily along with a mug of coffee.

  11. Arthur Franco April 2, 2014 at 3:32 am · Reply

    Thank you! Easy to install and it’s working on Opencart v1.5.6.1

  12. google advertising login March 31, 2014 at 4:51 am · Reply

    whoah this blog is fantastic i love reading your articles.
    Stay up the great work! You understand, a lot of individuals
    are searching round for this information, you can help them greatly.

  13. mark March 12, 2014 at 8:34 am · Reply

    thanks for this tutorials. got it! :)
    btw, i am a newbie in opencart and posting this sh*t here helps me a lot. Cool! :)

  14. devendra February 25, 2014 at 5:23 am · Reply

    thanks its working.. but still m unable to fully understand how the codes of opencart :(

  15. Everton February 4, 2014 at 5:57 pm · Reply

    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?

  16. Juan October 21, 2013 at 12:11 am · Reply

    Does this work on Opencart 1.5.6 ?

  17. God Father {BuTy BrotheRs} September 27, 2013 at 6:18 am · Reply

    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.

  18. Robert August 27, 2013 at 10:21 pm · Reply

    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?

  19. irfan April 23, 2013 at 10:37 am · Reply

    where is admin ?

    • Aaron June 4, 2013 at 5:55 pm ·

      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

  20. irfan April 16, 2013 at 10:20 am · Reply

    Can i call on specific categories on footer using php not a custom ..

  21. dilip April 11, 2013 at 6:15 am · Reply

    Its not working on opencart 1.5.5.1 please help!
    dilip@ebonyte.com

  22. Erkan Yilmaz March 25, 2013 at 2:09 am · Reply

    Does this tutorial work in OC 1.5.5.1? I tried several times but it doesn’t seems to work.

  23. Cleo February 24, 2013 at 4:59 am · Reply

    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

  24. Anuj February 14, 2013 at 7:10 am · Reply

    THANKS FOR THIS BEAUTIFUL, NICE & EASY TUTORIAL…. GREAT!!!

  25. François December 7, 2012 at 11:03 am · Reply

    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!

    • MarketInSG December 7, 2012 at 11:05 am ·

      you can do so easily by remove and replace it with your own design there

  26. Emanuel November 1, 2012 at 12:33 pm · Reply

    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

    • MarketInSG November 1, 2012 at 12:35 pm ·

      just add a link to your footer or something will do

    • Emanuel November 1, 2012 at 1:49 pm ·

      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.

    • MarketInSG November 1, 2012 at 2:13 pm ·

      in catalog/view/theme/*/template/common/header.tpl find and modify from there. it depends on your theme.

    • Emanuel November 1, 2012 at 2:29 pm ·

      Thanks. I’ll try to find what I should modify. My theme is the default theme just with a background and some different colors.

    • Emanuel November 1, 2012 at 2:33 pm ·

      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="”>

    • Emanuel November 1, 2012 at 2:48 pm ·

      Done.
      Thanks for the help.:D

  27. kostis September 24, 2012 at 1:37 pm · Reply

    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…..

  28. kostis September 21, 2012 at 1:28 pm · Reply

    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

    • MarketInSG September 21, 2012 at 1:30 pm ·

      That depends on how you coded it. maybe you can show how you coded?

  29. Svemirko September 20, 2012 at 10:25 am · Reply

    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!

    • MarketInSG September 20, 2012 at 10:27 am ·

      You will have to add additional layout. You can add layout from admin panel system > design > layout

    • Svemirko September 20, 2012 at 10:46 am ·

      Of course!
      Thanks again! :)

  30. whereissecondpart August 28, 2012 at 5:58 am · Reply

    where is the second part?

  31. MarketInSG August 25, 2012 at 4:17 am · Reply

    Part 2 will be out in a week! Stay tune!

  32. MarketInSG August 23, 2012 at 4:03 am · Reply

    Soon, no worries :)

  33. Sulfy August 10, 2012 at 7:47 pm · Reply

    wend it second part?

Trackbacks for this post

  1. How to create new pages? | Open Cart Know How
  2. Creating a Custom Page in OpenCart – part 2 - OpencartNews

Leave a Comment

comm comm comm