Page 1 of 1

Trying to add a custom category layout

Posted: Thu Apr 25, 2013 8:25 pm
by clinton4
Hi,

I am trying to create a custom category layout which i need to use for a specific category.

This is what i have done:

1. In System -> Design -> Layouts i have created a new layout.
- Layout Name: Category (catname)
- Store: Default
- Route: product/category_catname

2. In Catalog -> Categories -> Catname -> Design i have set Layout Override to my new Category (catname)

3. In /catalog/view/theme/mytheme/template/product/ i have made a copy of category.tpl and renamed it to category_catname.tpl, then made some changes to category_catname.tpl.

But when i now visit this category page, i cant se any of my changes. I looks like it falls back to the category.tpl file. Why is this happening?

I have read several docs and forum posts regarding layouts and my understanding is that i am doing it the right way, or?

Re: Trying to add a custom category layout

Posted: Thu Apr 25, 2013 10:02 pm
by justcurious
You don't need to create a new .tpl file.

What the layouts system does is allow you to change the layout around the content . The content is what is produced by your category.tpl, but you can have different modules around the content. For example you may have the categories module in the left column for normal categories, but for your custom layout, you may want to add the manufacturers module, Special Offers and / or Featured modules.

I suspect that you are wanting to display the content of your custom category differently to all of the other categories?

The layout system is not designed to do this

Re: Trying to add a custom category layout

Posted: Thu Apr 25, 2013 10:09 pm
by clinton4
I see, thanks for that info :)

You are right, i want to display the content of a spesific category differently then all other categories. Is there any recommended methods to achive this?

Re: Trying to add a custom category layout

Posted: Fri Apr 26, 2013 12:03 am
by rupaknepali
While inserting the category at the layout tab select your preferred tab by which the category showing style differs

Hope this helps you

Re: Trying to add a custom category layout

Posted: Fri Apr 26, 2013 12:09 am
by clinton4
rupaknepali wrote:While inserting the category at the layout tab select your preferred tab by which the category showing style differs

Hope this helps you
Sorry, i dont understand what you are saying :)

Re: Trying to add a custom category layout

Posted: Fri Apr 26, 2013 11:25 pm
by justcurious
If you will only ever have one specific category that you want the different page layout for, here's what to do:

In catalog/controller/product/category.php, find:

Code: Select all

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';
}
and replace with:

Code: Select all

			
if ($category_id == 25) {
   $this->template = $this->config->get('config_template') . '/template/product/category_catname.tpl';
} else {
   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';
   }
}
Change the 25 on the first line of the revised code to the category id of the category you are targetting.

If you want the flexibility to choose more than one category for the "special" template, this can also be done, but it is more complex. Pm me if it is something you want and would like my help

Kind regards

Re: Trying to add a custom category layout

Posted: Sat Apr 27, 2013 6:18 pm
by clinton4
Ok, thanks :)

Re: Trying to add a custom category layout

Posted: Fri Dec 21, 2018 6:56 pm
by dizovi
how can i do same for opencart 2.3.0.2