Single article alternative layout for just one category

Everything to do with Joomla! 3.x templates and templating.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
RemcoJanssen
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Wed Jun 19, 2019 12:21 pm

Single article alternative layout for just one category

Post by RemcoJanssen » Wed Jun 19, 2019 12:38 pm

Today I was working on something that (as always) seemed simple:

I wanted an alternative layout for all the articles within a specific category. So I created an override file:
/tempaltes/mytemplate/html/com_content/article/myalternativelayout.php

But no way to assign this to all articles within a category automatically. The only way (I know of) doing this is to go into every single article and select the new layout file. But that is a tedious job.

I came up with this solution, but there might be a better one...

in my default.php I placed the following code and copied the original code and the alternate code into the files that I require depending on the category.

Code: Select all

if ($this->item->catid != 13):
require_once JPATH_SITE . '/templates/mytemplate/html/com_content/article/article_default.php';
else:
require_once JPATH_SITE . '/templates/mytemplate/html/com_content/article/article_myalternativelayout.php';
endif;
- To state the obvious: going into your files to adjust the catid shouldn't be the way to go.
- Having sub-templates or layout files at our disposal, the require bit could be improved upon...

curious about other people thoughts

Remco

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 24986
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: Single article alternative layout for just one category

Post by pe7er » Wed Jun 19, 2019 1:57 pm

Looks like a proper solution!

RemcoJanssen wrote:
Wed Jun 19, 2019 12:38 pm
- To state the obvious: going into your files to adjust the catid shouldn't be the way to go.
Why not make it configurable via the Joomla back-end?
Add a default.xml to your template override in which you add a parameter to configure the categories to include or exclude.
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com

jonBuckner1
Joomla! Explorer
Joomla! Explorer
Posts: 428
Joined: Mon Nov 12, 2012 9:08 am

Re: Single article alternative layout for just one category

Post by jonBuckner1 » Wed Jun 19, 2019 9:51 pm

Did not know you could override xml files in html folder !!


Locked

Return to “Templates for Joomla! 3.x”