Monday, 11 May 2015

creating custom page in opencart

Create a file name 'static.php' in /catalog/controller/information/ folder


<?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());
    }
}
?>


Create a file name 'static.tpl' in /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; ?>

Create a file name 'static.php' in 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

?>
 

You have successfully created your own  custom page. You can now access the page you created from http://www.yourwebsite.com/index.php?route=information/static.

No comments:

Post a Comment