Post by MarketInSG » Sat Jan 10, 2015 10:13 am

Other tutorials:
Creating a Custom Page in OpenCart 1.5 (viewtopic.php?f=23&t=59542)
Creating a Custom Page in OpenCart 3 (viewtopic.php?f=23&t=186404)

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 {
  private $error = array();
    
  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.

    $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')
    );   
       
    $data['heading_title'] = $this->language->get('heading_title'); //Get "heading title" from language file.

    $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');

    // OpenCart 2.1 and below CHOOSE ACCORDINGLY
    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/static.tpl')) { //if file exists in your current template folder
      $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/information/static.tpl', $data)); //get it
    } else {
      $this->response->setOutput($this->load->view('default/template/information/static.tpl', $data)); //or get the file from the default folder
    }
    
    // OpenCart 2.2 and above CHOOSE ACCORDINGLY
    $this->response->setOutput($this->load->view('information/information', $data)); 
  }
}
Template file

Create a file name 'static.tpl' in /catalog/view/theme/default/template/information/

Code: Select all

<?php echo $header; ?>
<div class="container">
  <ul class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
    <?php } ?>
  </ul>
  <div class="row"><?php echo $column_left; ?>
    <?php if ($column_left && $column_right) { ?>
    <?php $class = 'col-sm-6'; ?>
    <?php } elseif ($column_left || $column_right) { ?>
    <?php $class = 'col-sm-9'; ?>
    <?php } else { ?>
    <?php $class = 'col-sm-12'; ?>
    <?php } ?>
    <div id="content" class="<?php echo $class; ?>"><?php echo $content_top; ?>
      <h1><?php echo $heading_title; ?></h1>
      YOUR OWN CONTENTS
      <?php echo $content_bottom; ?></div>
    <?php echo $column_right; ?></div>
</div>
<?php echo $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
Feel free to leave any comments behind ;D
Last edited by MarketInSG on Sun Mar 08, 2015 10:38 am, edited 2 times in total.


User avatar
Guru Member

Posts

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

Post by muhamedauda » Mon Jan 19, 2015 1:21 am

Hello
I did as you say on oc 2.0.1.1 and when call view give me blank page !!!!

aqwce.com | مصمم ومطور متاجر اليكترونية | @aqwce


New member

Posts

Joined
Sun Feb 02, 2014 7:26 pm

Post by muhamedauda » Mon Jan 19, 2015 1:28 am

I recreate and found i forget php letters , but whe call :

Code: Select all

http://localhost/testoc2cart/index.php?route=information/static
it display:

Code: Select all

Notice: Indirect modification of overloaded property ControllerInformationStatic::$data has no effect in /var/www/testoc2cart/catalog/controller/information/static.php on line 10
Notice: Indirect modification of overloaded property ControllerInformationStatic::$data has no effect in /var/www/testoc2cart/catalog/controller/information/static.php on line 12
Notice: Indirect modification of overloaded property ControllerInformationStatic::$data has no effect in /var/www/testoc2cart/catalog/controller/information/static.php on line 18
Notice: Indirect modification of overloaded property ControllerInformationStatic::$data has no effect in /var/www/testoc2cart/catalog/controller/information/static.php on line 24
I did this before on other examples and give me same error, and it !!!!!!!!!
Last edited by muhamedauda on Mon Jan 19, 2015 2:06 am, edited 1 time in total.

aqwce.com | مصمم ومطور متاجر اليكترونية | @aqwce


New member

Posts

Joined
Sun Feb 02, 2014 7:26 pm

Post by muhamedauda » Mon Jan 19, 2015 2:06 am

I changed the:

Code: Select all

$this->data
to

Code: Select all

$data
Now view display blank page !!!!

aqwce.com | مصمم ومطور متاجر اليكترونية | @aqwce


New member

Posts

Joined
Sun Feb 02, 2014 7:26 pm

User avatar
Guru Member

Posts

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

Post by skip » Wed Mar 04, 2015 10:47 pm

I got error show on image in attachement for 2.0.1.1 Where to search error ? Thanx

Attachments

Image 1.jpg

Image 1.jpg (102.65 KiB) Viewed 16589 times


Active Member

Posts

Joined
Mon May 09, 2011 9:57 pm

Post by MarketInSG » Thu Mar 05, 2015 8:50 am

my bad. Missed some codes.

Try copying again. Was missing

Code: Select all

$this->load->view(


User avatar
Guru Member

Posts

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

Post by skip » Thu Mar 05, 2015 6:54 pm

Still error, but work without:

Code: Select all

$this->response->setOutput($this->render());  
Thank you!

Active Member

Posts

Joined
Mon May 09, 2011 9:57 pm

Post by pta » Sun Apr 12, 2015 2:49 pm

Hi,

I think, the custom page is successfully created named static, and it is showing blank or displays home page.
Now, i want to put some texts or links, descriptions in that page.
Another inquiry is how to link this page from customer service section,

pls assist.

pta
New member

Posts

Joined
Sun Feb 08, 2015 11:54 am

Post by MarketInSG » Wed Apr 15, 2015 8:12 pm

the rest is up to your basic HTML knowledge to add links to your template on OpenCart.


User avatar
Guru Member

Posts

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

Post by aljawaid » Fri Apr 17, 2015 5:51 am

THIS is amazing... thank you I can now create custom pages in php without using the html editor

The best thing besides the header/footer staying intact is that you can apply a layout to information/static too

Thanks a lot for making it easier. :)

Total e-commerce newbie bravely testing OC v2.0.3.1 before rolling it live...getting there slowly, somehow. Maybe not. I dunno.


Active Member

Posts

Joined
Fri Oct 10, 2014 10:33 pm
Location - UK

Post by aljawaid » Fri Apr 17, 2015 5:59 am

Is there a way to add it to the sitemap and add SEO keyword to it too or is that a complicated task?

Just asking :) OCv2.0.2.0 by the way

Total e-commerce newbie bravely testing OC v2.0.3.1 before rolling it live...getting there slowly, somehow. Maybe not. I dunno.


Active Member

Posts

Joined
Fri Oct 10, 2014 10:33 pm
Location - UK

Post by jewelrana » Mon Oct 19, 2015 12:05 pm

MarketInSG wrote:This is a follow up to the previous topic http://forum.opencart.com/viewtopic.php?f=23&t=59542

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 {
  private $error = array();
    
  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.

    $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')
    );   
       
    $data['heading_title'] = $this->language->get('heading_title'); //Get "heading title" from language file.

    $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');

    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/static.tpl')) { //if file exists in your current template folder
      $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/information/static.tpl', $data)); //get it
    } else {
      $this->response->setOutput($this->load->view('default/template/information/static.tpl', $data)); //or get the file from the default folder
    }     
  }
}
Template file

Create a file name 'static.tpl' in /catalog/view/theme/default/template/information/

Code: Select all

<?php echo $header; ?>
<div class="container">
  <ul class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
    <?php } ?>
  </ul>
  <div class="row"><?php echo $column_left; ?>
    <?php if ($column_left && $column_right) { ?>
    <?php $class = 'col-sm-6'; ?>
    <?php } elseif ($column_left || $column_right) { ?>
    <?php $class = 'col-sm-9'; ?>
    <?php } else { ?>
    <?php $class = 'col-sm-12'; ?>
    <?php } ?>
    <div id="content" class="<?php echo $class; ?>"><?php echo $content_top; ?>
      <h1><?php echo $heading_title; ?></h1>
      YOUR OWN CONTENTS
      <?php echo $content_bottom; ?></div>
    <?php echo $column_right; ?></div>
</div>
<?php echo $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
Thanks a lot bro.....

User avatar
Newbie

Posts

Joined
Sun Oct 18, 2015 9:54 am
Location - Lakshmipur, Bangladesh

Post by armand1610 » Sun Aug 21, 2016 11:03 pm

Got the following:

Code: Select all

Notice: Error: Could not load template C:/xampp/htdocs/snipers-eye/catalog/view/theme/default/template/default/template/information/static.tpl! in C:\xampp\htdocs\snipers-eye\system\library\template\basic.php on line 26
changed the following:

Code: Select all

$this->response->setOutput($this->load->view('default/template/information/static.tpl', $data));
to this:

Code: Select all

$this->response->setOutput($this->load->view('information/static.tpl', $data));
Now all ok.

Newbie

Posts

Joined
Sun Aug 21, 2016 10:58 pm

User avatar
Guru Member

Posts

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

Post by paloc » Thu Oct 13, 2016 4:27 am

Is it possible to create the custom page and the necessary files and call it something other than 'static'? I have tried to do this unsuccessfully. I get a fatal error saying that the class ControllerInformationxxx does not exist, even if I do not change the name of the class, only the php file.

Thanks

Newbie

Posts

Joined
Wed Mar 18, 2015 8:32 am

Post by MarketInSG » Fri Oct 14, 2016 10:33 pm

You need to rename + replace all references of 'static' to the name you wish to use. Do note, no spaces or hyphens allowed.


User avatar
Guru Member

Posts

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

Post by paloc » Sat Oct 15, 2016 7:38 am

Thanks - I did get this to work. I failed to create a php file in my CUSTOM template folder.

Newbie

Posts

Joined
Wed Mar 18, 2015 8:32 am

Post by tpalella » Fri Jan 06, 2017 4:27 am

MarketInSG wrote:OpenCart 2.2 onwards changed, will need to update the topic again soon
Can you please give me a hint of what has changed. The route no longer works :(

Thank you!

t.

Newbie

Posts

Joined
Mon Dec 29, 2014 12:11 pm

Post by tpalella » Sat Jan 07, 2017 11:26 pm

Anyone knows what needs to be changed for 2.2+?

thank you!

Newbie

Posts

Joined
Mon Dec 29, 2014 12:11 pm
Who is online

Users browsing this forum: No registered users and 9 guests