Post by applab » Tue Sep 15, 2020 10:09 pm

Hi,

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.

User avatar
Newbie

Posts

Joined
Tue Dec 10, 2019 6:54 pm

Post by IP_CAM » Tue Sep 15, 2020 10:53 pm


Please don't send me OC Forum Personal Messages, just contact: jti@jacob.ch
---
OC 1.5.6.5 LIGHT Test Site: http://www.bigmax.ch/shop/
OC 1.5.6.5 V-PRO Test Site: http://www.openshop.li/shop/
My Github OC Site: https://github.com/IP-CAM
2'600+ FREE OC Extensions on the World's largest Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by letxobnav » Tue Sep 15, 2020 10:57 pm

there is a "Layout Override" option?

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.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by letxobnav » Tue Sep 15, 2020 11:07 pm

you can call any view you have created in a controller as long as you make sure they receive the $data they expect:

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.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by applab » Tue Sep 15, 2020 11:19 pm

@IP_CAM - the last of those modules (Custom Pages) looks interesting, however, for now I've found a solution requiring modification to just one file.
@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
then where the view is loaded add an 'if' statement...

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));
}

User avatar
Newbie

Posts

Joined
Tue Dec 10, 2019 6:54 pm

Post by letxobnav » Wed Sep 16, 2020 7:51 am

yes, you can use any condition really.
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.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by IP_CAM » Wed Sep 16, 2020 8:41 am

Well, you don't seem to be a Coder Newbie, as it looks, :laugh:
it's kind of refreshing, to at least once in a while find such 'Newbies' here ... :D
Good Luck! ;)
Ernie

Please don't send me OC Forum Personal Messages, just contact: jti@jacob.ch
---
OC 1.5.6.5 LIGHT Test Site: http://www.bigmax.ch/shop/
OC 1.5.6.5 V-PRO Test Site: http://www.openshop.li/shop/
My Github OC Site: https://github.com/IP-CAM
2'600+ FREE OC Extensions on the World's largest Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by applab » Wed Sep 16, 2020 10:03 pm

letxobnav wrote:
Wed Sep 16, 2020 7:51 am
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.
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.

User avatar
Newbie

Posts

Joined
Tue Dec 10, 2019 6:54 pm

Post by applab » Wed Sep 16, 2020 10:09 pm

IP_CAM wrote:
Wed Sep 16, 2020 8:41 am
Well, you don't seem to be a Coder Newbie, as it looks, :laugh:
it's kind of refreshing, to at least once in a while find such 'Newbies' here ... :D
Good Luck! ;)
Ernie
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.

User avatar
Newbie

Posts

Joined
Tue Dec 10, 2019 6:54 pm

Post by IP_CAM » Wed Sep 16, 2020 11:43 pm

Checked out your Github repo. Pleasantly surprised to find that 1.5.6 still has it's fans ...
Well, 1.5.6.(5) is the only Version, able to handle PHP v.7.4.9, by only replacing the system 'encryption.php'
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 ... :laugh:

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 ... :D 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 ... :crazy: :laugh:

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

Please don't send me OC Forum Personal Messages, just contact: jti@jacob.ch
---
OC 1.5.6.5 LIGHT Test Site: http://www.bigmax.ch/shop/
OC 1.5.6.5 V-PRO Test Site: http://www.openshop.li/shop/
My Github OC Site: https://github.com/IP-CAM
2'600+ FREE OC Extensions on the World's largest Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland
Who is online

Users browsing this forum: No registered users and 17 guests