I would ask for a little help
I would like to create another template for my three categories (category ID 119 / ID 125 / ID 140).
I found one solution for version 2.2.0.0.
find $this->response->setOutput($this->load->view('product/category', $data));
in catalog/controller/product/category.php
and replace it with above codes, here is:
$config_theme = $this->config->get('config_theme') == 'theme_default' ? 'default' : $this->config->get('config_theme'); if (file_exists(DIR_TEMPLATE . $config_theme . '/template/product/category_' . $category_id . '.tpl')) {
$view = 'product/category_' . $category_id;
} else {
$view = 'product/category';
}
$this->response->setOutput($this->load->view($view, $data));
Link to the solution:
<https://stackoverflow.com/questions/407 ... 9#53498989>
I created category_119 however, it does not work. I tried to complete this code but nothing works
perhaps I have to complete code by:
* entering the name of my new template (category_119) = but I do not know exactly where to sign
* enter the category ID (119/125/140) = = but I do not know exactly where to sign
* probably enter the name of my template - although I have default - (Default (Default Store Theme)
How to enter correctly, because I try but it fails.
Thank you for your help
Best Regards. Adam.
I would like to create another template for my three categories (category ID 119 / ID 125 / ID 140).
I found one solution for version 2.2.0.0.
find $this->response->setOutput($this->load->view('product/category', $data));
in catalog/controller/product/category.php
and replace it with above codes, here is:
$config_theme = $this->config->get('config_theme') == 'theme_default' ? 'default' : $this->config->get('config_theme'); if (file_exists(DIR_TEMPLATE . $config_theme . '/template/product/category_' . $category_id . '.tpl')) {
$view = 'product/category_' . $category_id;
} else {
$view = 'product/category';
}
$this->response->setOutput($this->load->view($view, $data));
Link to the solution:
<https://stackoverflow.com/questions/407 ... 9#53498989>
I created category_119 however, it does not work. I tried to complete this code but nothing works
perhaps I have to complete code by:
* entering the name of my new template (category_119) = but I do not know exactly where to sign
* enter the category ID (119/125/140) = = but I do not know exactly where to sign
* probably enter the name of my template - although I have default - (Default (Default Store Theme)
How to enter correctly, because I try but it fails.
Thank you for your help
Best Regards. Adam.
I changed the template in the category.tpl by just saying
<?php if ($heading_title =='name of your category you want to change') { ?>
Your new template code goes here
<?php } ?>
<?php if ($heading_title <>'name of your category you want to change') { ?>
Your regular category code
<?php } ?>
<?php if ($heading_title =='name of your category you want to change') { ?>
Your new template code goes here
<?php } ?>
<?php if ($heading_title <>'name of your category you want to change') { ?>
Your regular category code
<?php } ?>
Really can't see any benefit in editing the template!
Why?
This 'solution' is limited to one language only.
If you are using more languages, you have to edit always the code inside the template - or adding a if .. then .. else or switch.
The easiest (and most correct, because change is done inside the controller - you should avoid to mix html and php inside any template), is to change this in the controller:
from:
to:
But this code is limited, because what if you have a category without a custom template?
Then, you should do this instead (check before if exist, otherwise use standard):
Done once, always useable.
Why?
This 'solution' is limited to one language only.
If you are using more languages, you have to edit always the code inside the template - or adding a if .. then .. else or switch.
The easiest (and most correct, because change is done inside the controller - you should avoid to mix html and php inside any template), is to change this in the controller:
from:
Code: Select all
$this->response->setOutput($this->load->view('product/category', $data));
Code: Select all
$this->response->setOutput($this->load->view('product/category' . $category_info['category_id'], $data));
Then, you should do this instead (check before if exist, otherwise use standard):
Code: Select all
$tpl = 'category_' . $category_info['category_id'];
if( !file_exists( DIR_TEMPLATE . $tpl . '.tpl' ) ) {
$tpl = 'category';
}
$this->response->setOutput($this->load->view('product/' . $tpl, $data));
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
Hello, thank you for your help - you're right I actually use two languages and it would be less work for your solution
I have a standard template then just use it:
$this->response->setOutput($this->load->view('product/category' . $category_info['category_id'], $data));
however, now I would have to create a file for each category - if I do not have one - it's not loading standard ( category.tpl )
there is no note that if it does not find the category_xxx = it loads the standard category
how to add it correctly??
Thank you very much for your help
I have a standard template then just use it:
$this->response->setOutput($this->load->view('product/category' . $category_info['category_id'], $data));
however, now I would have to create a file for each category - if I do not have one - it's not loading standard ( category.tpl )
there is no note that if it does not find the category_xxx = it loads the standard category
how to add it correctly??
Thank you very much for your help
As already written:
Code: Select all
$tpl = 'category_' . $category_info['category_id'];
if( !file_exists( DIR_TEMPLATE . $tpl . '.tpl' ) ) {
$tpl = 'category';
}
$this->response->setOutput($this->load->view('product/' . $tpl, $data));
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
still a problem
**** when I exchange for:
$this->response->setOutput($this->load->view('product/category' . $category_info['category_id'], $data));
it works but then I must have an individual template for each category
***** when I exchange for (or insert)
$tpl = 'category_' . $category_info['category_id'];
if( !file_exists( DIR_TEMPLATE . $tpl . '.tpl' ) ) {
$tpl = 'category';
}
$this->response->setOutput($this->load->view('product/' . $tpl, $data));
do not find new categories
***** when I exchange for:
$this->response->setOutput($this->load->view('product/category' . $category_info['category_id'], $data));
$tpl = 'category_' . $category_info['category_id'];
if( !file_exists( DIR_TEMPLATE . $tpl . '.tpl' ) ) {
$tpl = 'category';
}
error.
Parse error: syntax error,
What I'm doing wrong is not working?
**** when I exchange for:
$this->response->setOutput($this->load->view('product/category' . $category_info['category_id'], $data));
it works but then I must have an individual template for each category
***** when I exchange for (or insert)
$tpl = 'category_' . $category_info['category_id'];
if( !file_exists( DIR_TEMPLATE . $tpl . '.tpl' ) ) {
$tpl = 'category';
}
$this->response->setOutput($this->load->view('product/' . $tpl, $data));
do not find new categories
***** when I exchange for:
$this->response->setOutput($this->load->view('product/category' . $category_info['category_id'], $data));
$tpl = 'category_' . $category_info['category_id'];
if( !file_exists( DIR_TEMPLATE . $tpl . '.tpl' ) ) {
$tpl = 'category';
}
error.
Parse error: syntax error,
What I'm doing wrong is not working?
Sorry. 2.2.x is a totally crap!
Here the tested and working code:
Here the tested and working code:
Code: Select all
$tpl = 'category_' . $category_info['category_id'];
if( !file_exists( DIR_TEMPLATE . $this->config->get('theme_default_directory') . '/template/product/' . $tpl . '.tpl' ) ) {
$tpl = 'category';
}
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
works - it's great
thank you very much for the moment of your time and help me.
Best Regards.
Adam.
thank you very much for the moment of your time and help me.
Best Regards.
Adam.
Pleasure to help.adam.skrzynka wrote: ↑Fri Nov 30, 2018 8:10 pmworks - it's great
thank you very much for the moment of your time and help me.
Best Regards.
Adam.
Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.
Who is online
Users browsing this forum: No registered users and 72 guests