Opencart Version 3.0.3.2
Theme: Default (with minor CSS tweaks)
I would like just some of my categories to use a different twig template rather than the default one. I thought I might be able to do this using a custom layout and then applying this using the 'Layout Override' option on the Categories->Design tab. However, I can't see any way to specify which twig template gets used.
Is this even possible?
I'm new to OC development but an old hand with HTML/CSS/PHP/JS (& Twig) so happy to dig into code if necessary.
Any pointers much appreciated.
Thanks.
/Theme/,/Controller/, /Language/, and eventually /Model/ Files too, to make such possible.
Ernie
https://www.opencart.com/index.php?rout ... n_id=27585
https://www.opencart.com/index.php?rout ... n_id=19777
https://www.opencart.com/index.php?rout ... n_id=34613
https://www.opencart.com/index.php?rout ... n_id=27917
https://www.opencart.com/index.php?rout ... n_id=39573
https://www.opencart.com/index.php?rout ... n_id=24113
My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
Code: Select all
// use different views for different categories
$cat_view_1 = array(23,44,66,2,55);
$cat_view_2 = array(16,53);
if (in_array($category_info['category_id'], $cat_view_1)) {
$this->response->setOutput($this->load->view('product/category_view_1', $data));
} elseif (in_array($category_info['category_id'], $cat_view_2)) { {
$this->response->setOutput($this->load->view('product/category_view_2', $data));
} else {
$this->response->setOutput($this->load->view('product/category', $data));
}
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
@letxobnav - Yes, I thought I might be able to use that but I couldn't find a way to use an alternate template for the same route (product/category)
@letxobnav - Just seen your 2nd post, it's along the same lines as what I've done but I was able to use a conditional instead of hard-coding category id's.
My requirement was to have an alternative twig template for any categories that don't have sub-categories, so here's what I've done, I'm not sure I've gone about it the best way so I would still appreciate any feedback.
1) create new twig file /theme/default/template/product/category2.twig (copied category.twig then modified as required)
2) copy /catalog/controller/product/category.php to /system/storage/modification/catalog/controller/product/category.php
3) modified the copy of category.php as follows:
after the call to getCategories set a boolean depending on whether the $results array is empty
Code: Select all
$results = $this->model_catalog_category->getCategories($category_id);
$lowest_level = count($results) ? false : true; // added
Code: Select all
if($lowest_level) {
$this->response->setOutput($this->load->view('product/category2', $data));
} else {
$this->response->setOutput($this->load->view('product/category', $data));
}
The layouts can only be defined on route level with/without a wildcard, besides a layout only defines which modules are statically placed if and where on a layout, no dynamics there.
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
it's kind of refreshing, to at least once in a while find such 'Newbies' here ...
Good Luck!
Ernie
My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.
Still getting my head around layouts, I find it easier to just edit the twig files but I guess I should learn to do things the 'proper' way ;-)
The ability to apply a custom twig template to a layout would be nice, though there might be implications I haven't thought of.
Thanks Ernie :-)
Many years of coding under my belt, and thankfully the Opencart source code is quite easy to find your way around.
Checked out your Github repo. Pleasantly surprised to find that 1.5.6 still has it's fans, that's the last version I used and I remember it fondly.
Well, 1.5.6.(5) is the only Version, able to handle PHP v.7.4.9, by only replacing the system 'encryption.php'Checked out your Github repo. Pleasantly surprised to find that 1.5.6 still has it's fans ...
File, and no other Version ever offered a comparable Range of free Extensions. It's a Goldmine for those,
looking for a speedy & simple free Solution, and so far, I just don't see any Forum Postings, complaining
about technical or security-related Problems. So, why should I care about later Releases, as long as my
OC Baby works so well ...
But from the Developer Point of View, 1.5.6.x is not big Business anymore, it's therefore understandable,
that some of the DEV's don't seem to like it. But that's sure not my Problem, to me, it's just another OC,
like every other Version too. An some will further use it, it's one reason, to have it on Github, in addition
to most OC other Version Github-placed OC Extensions, available on my Github Repository Site. And
should I ever run into Problems, I can count on some Friends, willing and able to be of help ... It also
keeps me from playing 'latest' Versions Tester, required, to move up every few months again, to eventually
some day end up with something, as solid as the one I use already now ...
Still, I don't even have a 'real' Online Shop, and I don't need one either, it's more, to keep Mr. Alzheimer
away as far as possible, and my self-trained english intact, because with 74+, I'm probably one of the oldest
Fellows around here.
Ernie
My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.
Users browsing this forum: No registered users and 60 guests