Solved

Joomla 2.5 alternate layouts for category

Posted on 2013-06-28
6
1,399 Views
Last Modified: 2013-07-13
I'm a competent PHP programmer, but fairly new to Joomla and its voodoo ways.

I have a category named "tuesday-archive".  I have a series of old newsletter pages, each of which is an article belonging to that category.  I also have a module (type "Articles Category") which generates a list of all articles belonging to the tuesday-archive category.  I have an article (call it the "list" page) which renders that module.  My menu item points to the list page, which is assigned to a different category.

The overwhelming majority of these old newsletters came with their own full-page HTML, so displaying them in my site's current template is inappropriate.  I need to display them in a "blank" template.  I created an alternate layout by creating a very simple template file and saving it as /templates/mytemplate/html/com_content/category/news-archive.php.  The content is extremely basic:
<html>
  <head>
    <jdoc:include type="head" />
    <link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/mytemplate/css/template.css" type="text/css" />
  </head>
  <body>
    <jdoc:include type="component" />
  </body>
</html>

Open in new window


When I go the category "tuesday-archive" in the category manager, under "Basic Options", I can see news-archive as a selectable option in the Alternate Layout drop-down.  It is selected, but browsing to one of the newsletter articles continues to use the full template for the site.  

In my research, I've found that the alternate layout assignment at the category level will not be applied if a menu item pointing to the category exists.  That is not the case here - the menu item is pointed at the list page, which is assigned to a different category.  Still, if I assign the alternate layout to that menu item instead of the category, then the destination list page, and all the archived articles, will use the alternate layout as directed.  This would be great, except the list page does need the normal site template.

What do I need to do to assign an alternate layout to any article belonging to a specific category, and be able to arrive there from normal menu navigation?
0
Comment
Question by:Steve Bink
  • 2
6 Comments
 
LVL 24

Assisted Solution

by:lenamtl
lenamtl earned 50 total points
Comment Utility
Hi,

The old way was to create another template and assign it to the categories.

You can use layout overrides but seems not to work all the time depending of the template. I guess you have already read those pages but just in case:

http://docs.joomla.org/Layout_Overrides_in_Joomla_2.5
http://www.ostraining.com/blog/joomla/alternative-layouts-for-modules/

A possible solution:
http://irislines.com/blog/puzzled-by-alternative-layouts-not-working.html

*Suggestion when something is not working in Joomla I always switch to Joomla  default template and make my tests, some of free or premium templates have different code or miss some Joomla code.

Maybe an extension already exist and does what you need, you can check this link:
http://extensions.joomla.org/extensions/news-display/articles-display/latest-news
0
 
LVL 50

Accepted Solution

by:
Steve Bink earned 0 total points
Comment Utility
I have read the doc page, and the ostraining.com procedure is essentially what I did to create my alternate layout.  In this case, I copied the primary site template and just removed everything.  The code I posted above is literally all there was in the file.   We are trying to avoid using overrides as a matter of policy.

It looks very much like I got caught up in the problem described in the irislines.com post.  In this case, the alternate layout showed up and was selectable in the category manager, but it would not apply.  My menu link was to an article which loads a module showing all the posts in the category - I was hoping the abstraction would make a difference.  In any case, the layout will not apply unless it is also applied to the menu item, and the menu item article cannot use the alternate layout.

What I eventually ended up doing is copying the main site template again.  Instead of removing everything, I inserted PHP logic to determine if the request is for the listing or a specific article.  If it is the listing, the normal template is used, otherwise, the stripped template it used.  I applied this alternate layout to the menu item, and it is working as desired.
<html>
  <head>
    <jdoc:include type="head" />
  </head>
  <body>
    <?php 
      /* if the URL includes 'tuesday-transit-news-archive', this is an actual news 
          archive article.
          Many of them come with full-page HTML included, so they are rendered 
          outside of the template.
          If 'tuesday-transit-news-archive' does not appear, this is probably the 
          listing page, which requires the template.  
          The template below is an exact copy of the site's default template.
      */
      if (strpos($this->base,'tuesday-transit-news-archive')===false) { ?>
       <!-- the site's default template - HTML, <jdoc />, etc -->
     <?php } else { ?>
       <jdoc:include type="component" style="xhtml" />
     <?php } ?>
  </body>
</html>

Open in new window

0
 
LVL 50

Author Closing Comment

by:Steve Bink
Comment Utility
I engineered my own solution.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Read about how to choose the best possible content marketing agency to suit your needs. Content marketing has become an integral part of running a successful tech business, so it is wise to be informed.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now