The Joomla! ® Community Magazine

Tutorial: Taking Advantage of Alternative Layouts for Articles and Modules

Written by Scott Greenwald | Friday, 01 February 2013 00:00 | Published in 2013 February
Template overrides are a great way to customize your Joomla site. But what if you want to use different article or module layouts throughout your site? Joomla's strict MVC architecture makes that a breeze with the "Alternative Layouts" feature.

If you've ever created a template override, then you'll find the process of creating alternative layouts to be nearly identical. The only difference is that your alternative layouts will appear as an option alongside the default layouts, instead of completely overriding them. The following examples are based on Joomla 2.5.x, and should also work for the Joomla 3.x series.

Alternative Layouts for Articles:

  1. Locate the default layout in components/com_content/views/article/tmpl/default.php
  2. Copy this to your template's html folder: templates/[your_template]/html/com_content/ (create these folders if they don't already exist)
  3. Change the file name. We'll call it myarticle.php

myarticle

You can edit anything in this new layout. For example, I'll change the print & email icons to appear above the article title instead of below it. And I'll change the article title to an H1 tag.

article overrides

To use your new layout, just go to your Article's Options and select it from the Alternative Layout menu. 

alt-article-layout

And here on the front-end is what our "myarticle" layout looks like compared to the default:

article layouts

Alternative Layouts for Modules:

Follow the same process to make alternative layouts for Modules! I'll use the Custom HTML module for this example.

  1. Locate the default layout in modules/mod_custom/tmpl/default.php
  2. Copy this file to your template's html folder: templates/[your_template]/html/mod_custom/
  3. Change the file name. We'll call this one mymodule.php

mymodule

Your new layout will appear in your module settings, under Advanced Options > Alternative Layout.

alt-module-layout

Alternative layouts can be created for nearly any type of module. Fellow JCM author Steve Burge has a great example of how to create an alternative layout for the Menu Module. Check that out on the OS Training Blog: How to Use Joomla's Alternative Layouts for Modules

Tip: Only create alternative layouts when absolutely necessary, such as editing html tags or changing the position of elements. For things like editing styles or colors, it's a best practice to make those changes within your template's CSS files rather than inside the layouts. Keep in mind that you can also use Module Class Suffixes and Page Classes to access CSS styles.

I hope this demonstration has shown you how powerful the Alternative Layouts feature can be. Virtually any of the content in the core layouts can be changed to suit your needs. 

And if you're a template developer, then consider including Alternative Layouts in your designs. This is a major feature that very few template providers are taking advantage of. 

Go forth and get creative with Alternative Layouts (and be careful if you're not an experienced programmer!).

Have you used Alternative Layouts in a creative way? Let us know about it in the comments below.

Read 11088 times
Tagged under Sitebuilders, English
Scott Greenwald

Scott Greenwald

Scott Greenwald runs the popular video tutorial site JoomlaDirect.com. He's an experienced front-end developer with roots in design and user interaction. Scott works as a fulltime freelancer from his home office in Tokyo Japan, where he specializes in custom Joomla development and template design for clients all over the world.

Leave a comment

Make sure you enter the (*) required information where indicated.

[b] [i] [u] [s] [url] [quote] [code] [img]   

Comments (16)

  • avatar
    • 0
    • 0
    William White

    It is good to see many new options coming to the core, especially when this article is wrapped inside

  • avatar
    • 0
    • 0
    Yiannis

    Thank you for your instructions Scott.
    I would like to create a different skin at a specific article.
    I hope to succeed.

  • avatar
    • 0
    • 0
    Neil McGuire

    Thanks Scott for the article. I just recently made an alternative layout for my blog with K2. It took time to wade through the issues, but the effort was worth it. Please take a look and tell me what you think. All-Right Web Design/Tips.

  • avatar
    • 0
    • 0
    shaz

    It looks like it doesn't work in J3 (3.0.3). Could you test it?

  • avatar
    • 0
    • 0
    Kaloyan Banev

    I must admit that I haven't tried anything similar since Joomla 1.5 when I was using heavily amended article layout for real estate project. Probably I will gonna try it again after I migrate my recent project to Joomla v3.

  • avatar
    • 0
    • 0
    Simon

    Hi Scott,

    thanks for this article.
    In the part "Alternative Layouts for Articles", point 2, you have a little mistake :


    templates/[your_template]/html/com_content/ should be :

    templates/[your_template]/html/com_content/article

    No?

    Thanks again ;)

  • avatar
    • 0
    • 0
    Elton Mesquita

    Yeah, the Joomla's override system is really great! If you use K2 it has the same feature but call it templates. I've discovered how awesome it is while I was building a big portal and could not use a lot of extensions. Almost everything on it is just a override, the modules, the slideshows, the article, the items lists and so on.
    This way I've got to keep the code really clean, fast and the way I wanted to!
    The end result is great!!!
    I'll probably think a lot of times before installing any extension in my Joomla's installations and try to do it with just overrides :D

    Here's the page: http://oestilo.com.br/
    Every module in the homepage is a override from K2's content module. Besides it I've built some K2's templates (overrides) for the internal section.
    This was the biggest and the cleanest page I've ever built with Joomla :D

    Thanks for the article, it'll help a lot of people!!!
    Keep up the good work ;D

  • avatar
    • 0
    • 0
    Jhay Khay Cee

    Thank you! This is perfect if you have articles for special occasions like Valentines Day and Christmas!

  • avatar
    • 0
    • 0
    Chris Hoefliger

    I've never really thought about this possibility, but now that you mention it...
    Thanks alot, this is a very handy feature.

  • avatar
    • 0
    • 0
    arest

    Dear Scott, great work ! And can I translate your article into Chinese ? Thanks ~~

  • avatar
    • 0
    • 0
    Scott Greenwald

    Absolutely! The Joomla Community magazine is always looking for multi-lingual content. If you're not already a contributor, then go ahead and sign up using the link on the sidebar!

  • avatar
    • 0
    • 0
    leilweb

    As I know, if the article is connected to the menu item, alternative layout for this article doesn't work, and we have to copy .xml file also, yes?

  • avatar
    • 0
    • 0
    Nick

    Hi Scott,
    Based on your article and a snap from stackoverflow I created a tutorial for custom article templates tied to a menu (Menu overrides article template).
    [url=]http://www.inkhorn.ca/joomla-custom-article-template-with-menu-link/[/url]
    Hope it helps some others!
    Thanks for your tutorial!

  • avatar
    • 0
    • 0
    Gabor

    Nick is great!

    I spend hours to figure out why not work Scott's method... hours.

    Thank you Nick, thank you Scott.

  • avatar
    • 0
    • 0
    gregor de lijzer

    Seems pretty easy! I wonder why it is that complicated to create an alternative print layout. Any idea?

    great article by the way :-)