Webocreation

Saturday, April 16, 2011

Opencart Views






Opencart Views

A Opencart view is simply a web page, or a page fragment, like a header, footer, sidebar, etc. In fact, views can flexibly be embedded within other views (within other views, etc., etc.) if you need this type of hierarchy.
Opencart Views are never called directly; they must be loaded by an opencart controller. Remember that in an MVC framework, the Controller acts as the traffic cop, so it is responsible for fetching a particular view. If you have not read the Opencart Controller page you should do so before continuing.
Using the example controller we created in the opencart controller page, let's add a view to it.

Creating a View

Opencart View is located in the

catalog/view/theme/template_folder_name/template/subdirectory/file_name.tpl


The extension of the opencart view file is .tpl
Now on the file we write the html code.

Save the file as hello.tpl in the 

catalog/view/theme/template_folder_name/template/subdirectory/

Let me describe the view file the variable is defined in the controller and the $header is the path to the header file as





Loading a opencart view or Loading multiple views

 

$this->children = array(
                                'common/column_right',
                                'common/column_left',
                                'common/footer',
                                'common/header'
);
This will automatically load the header, column_right, column_left, footer and header.
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category.tpl')) {
 $this->template = $this->config->get('config_template') . '/template/product/category.tpl';
} else {
$this->template = 'default/template/product/category.tpl';
}
These lines in the controller say that load the file if it does not exist        

No comments:

Post a Comment