kndwsu
kndwsu

Reputation: 381

How to change default home page in opencart

I am new to opencart. I just want two main pages, one will be listing all the products(by default in opencart) and the other will describes about the company. So how can i change the default home page.

These two pages should have different headers. How can i set the route for this kind of pages.

Ya i tried as follows

created new file under common as default.tpl

In my home.tpl I used

<?php if(!isset($this->request->get['route'])){
    echo $header;
}else{
    echo $default;
}
?>

But it is not rendering default. I also created a controller under controller/common/default.php with following lines

<?php
class ControllerCommonDefault extends Controller {
    public function index() {
        $this->template = $this->config->get('config_template') . '/template/common/default.tpl';
        $this->render();
    }
}

Upvotes: 0

Views: 20927

Answers (2)

Jem
Jem

Reputation: 392

It would be easier to write a seperate header file... if you open catalog/controller/common/home.php you will find the following code

    $this->children = array(
        'common/column_left',
        'common/column_right',
        'common/content_top',
        'common/content_bottom',
        'common/footer',
        'common/header'
    );

you could change this to

    $this->children = array(
        'common/column_left',
        'common/column_right',
        'common/content_top',
        'common/content_bottom',
        'common/footer',
        'common/headerhome'
    );

and then open:

catalog/view/theme/default/common/home.tpl

and find the following line:

<?php echo $header; ?>

and change it to:

<?php echo $headerhome; ?>

and then copy:

catalog/controller/common/header.php

and rename it

headerhome.php

and then open

catalog/controller/common/headerhome.php

and find the following line

class ControllerCommonHeader extends Controller {

and change to:

class ControllerCommonHeaderhome extends Controller {

then find:

$this->language->load('common/header');

and change to:

$this->language->load('common/header');

then find the following code:

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/header.tpl')) {
    $this->template = $this->config->get('config_template') . '/template/common/header.tpl';
} else {
    $this->template = 'default/template/common/header.tpl';
}

and change it to:

    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/headerhome.tpl')) {
        $this->template = $this->config->get('config_template') . '/template/common/headerhome.tpl';
    } else {
        $this->template = 'default/template/common/headerhome.tpl';
    }

and then copy

catalog/view/theme/default/common/header.tpl

and rename to:

catalog/view/theme/default/common/headerhome.tpl

then copy:

catalog/language/english/common/header.php

and rename to:

catalog/language/english/common/headerhome.php

you can then edit the following file to reflect the style changes that you want:

catalog/view/theme/default/common/headerhome.tpl

you can then edit the following file to reflect the language changes that you want:

catalog/language/english/common/headerhome.php

This means that the home page will show headerhome and all other pages will show the standard header, which if you are only going to have two pages like you said earlier this solves your problem...

Upvotes: 7

Sankar V
Sankar V

Reputation: 4128

$this->request->get['route']

You will get the current page path using this piece of code. Write a condition based on that in your common/header.php controller file and use separate template files.

Upvotes: 0

Related Questions