Community Forums

Set Category, Product n Information Spesific Template

Set Category, Product n Information Spesific Template

Postby qahar » Sat Jun 16, 2012 4:40 am

In this tutorial we will learn on how to make spesific template for Category, Product and Information. Some post forum already mention this with various method, but I try to use the simplest method.

And before we continue, I want to clarify that Template refer to .tpl file on Opencart theme. Regardless the theme you use, word "template" refer to .tpl file.

What we want to achieve here?
  1. Load spesific template for category, product and information based on the id.
  2. If spesific template is not available, then use the general template. ex. category.tpl, product.tpl, information.tpl
  3. The same thing applied to load stylesheet spesifically.

In this tutorial I only show you how to achieve with Category, and the same method is applied for Product and Information. And you can download the vQmod file that already modificate the Category, Product and Information at bottom of the page.

  1. Open catalog\controller\product\category.php
  2. Load spesific template:
    Code: Select all
    // FIND :
    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';
    }

    // REPLACE :
    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category_'.$category_id.'.tpl')) {
        $this->template = $this->config->get('config_template') . '/template/product/category_'.$category_id.'.tpl';
    }
     elseif (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';
    }

    /* Explanation :
    1. The code will search spesific template based on it ID. ex: category_18.tpl.
    2. If the spesific template is not available, Opencart will use the general template of active theme (category.tpl).
    3. If the template of spesific theme is not available, Opencart will use template from default theme.
    */ 

  3. Load spesific stylesheet:
    Code: Select all
    // FIND :
    $this->document->setTitle($category_info['name']);

    // PUT BEFORE :
    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/stylesheet/category_'.$category_id.'.css')) {
        $this->document->addStyle('catalog/view/theme/' . $this->config->get('config_template') . '/stylesheet/category_'.$category_id.'.css');
    }

    /* Explanation :
    1. The code will search spesific stylesheet based on it ID. ex: category_18.css.
    2. If the spesific stylesheet available then load it, if not then do nothing.
    */ 

  4. Example of folder structure:
      stylesheet/
        stylesheet.css
        category_18.css
        product_17.css
        information_3.css
      template/
        product/
          category.tpl
          category_18.tpl
          product_17.tpl
        information/
          information.tpl
          information_3.tpl

category_spesific_template.png
category_spesific_template.png (36.23 KiB) Viewed 5198 times


category_product_information_spesific_template.xml
(3.41 KiB) Downloaded 357 times


Note:
Since most user unable to reply this post, if you want to suggest think to improve this tutorial you can PM me. No Question Please!
Make new post on Support Forum if you have any question.
My product: Opencart Blog Manager Free System Information
OpencartNews - News, Tutorial n Tips - Common OpenCart Errors and How to Solve Them
Don't forget to add [SOLVED] to your Thread Title (first post), if your issue is solved.
User avatar
qahar
 
Posts: 1647
Joined: Tue Jun 29, 2010 2:24 pm
Location: Indonesia

Re: Set Category, Product n Information Spesific Template

Postby avvici » Thu Aug 09, 2012 11:22 am

Nice one man. Just saw this tut.
Image Image
User avatar
avvici
 
Posts: 4287
Joined: Tue Apr 05, 2011 4:09 am
Location: Charlotte, NC


Return to Themes

Who is online

Users browsing this forum: No registered users and 2 guests

Hosted by Arvixe Web Hosting