Solved

Joomla 2.5 alternate layouts for category

Posted on 2013-06-28
6
1,421 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 25

Assisted Solution

by:lenamtl
lenamtl earned 50 total points
ID: 39305196
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 51

Accepted Solution

by:
Steve Bink earned 0 total points
ID: 39306695
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 51

Author Closing Comment

by:Steve Bink
ID: 39323052
I engineered my own solution.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

691 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