Using Joomla’s Template and Layout Override

Written by Pat Fortino on . Posted in Joomla Core Features

Joomla has two powerful design features: Template Overrides and Layout Overrides. You can use either of these override functions to change look or functionality of a component, module, or menu item type.

For example, say you want to create an override for an article to move the Email and Print icons from the top of the page to the bottom of the page. You could directly modify the template for articles, but that would be a hack to the Joomla core files. Unfortunately, it would be overwritten every time you updated Joomla. As a result, it makes more sense to create a template or layout override.

The Difference Between a Joomla Template Override and Layout Override

The difference between the template and layout override is that a template override is applied globally and a layout override is manually assigned. Using the example of the article modification to move the icons to the bottom of the page, a template override would change ALL articles automatically. On the other hand, a layout override would require that you manually assign the override to specific articles.

Both methods have their use. When you want to change the default behavior, create a template override. When you want to create a custom override that you can apply manually to specific items, use the layout override.

There is no need to explain how to create the two different overrides since it is clearly explained in the Joomla documents:

However, the Joomla documents DO NOT explain clearly how to apply the layout overrides. It is critical that you understand where to apply the layout override and what type of override to use:

Template Override

If you create a Template Override, it will be automatically applied globably; for example, you copied /components/com_content/articles/views/tmpl/article/default.php to

/templates/your-template/html/com_content/article/default.php

In this case, all articles would use the template override.

Layout Override

If you create a Layout Override, you will have to manually apply it to specific articles NOT LINKED TO THE MENU. If an article is linked to the menu, you need to apply an Alternative Menu Item Layout Override. 

Use Layout Overrides to modify articles not linked to the menu; for example, category list and category blog articles are not linked directly to the menu.

For example, you copied /components/com_content/articles/views/tmpl/article/default.php to

/templates/your-template/html/com_content/article/newdefault2.php

Note the name change. By changing the name of default.php to newdefault2.php, you tell Joomla that this is a layout override instead of a template override.

To apply this example layout override to an article, open the article to which you want to apply the override, click Article Options, and from the Alternative Layout list, select the new layout. In this case, newdefault2.

Screen Shot 2012-01-04 at 12.03.37 PM

Alternative Menu Items

Use Alternative Menu Items Layout Overrides to apply an override to an article linked directly to the menu.

For example, you copied

/components/com_content/articles/views/tmpl/article/default.php to

/templates/your-template/html/com_content/article/newdefault.php


And you copied

/components/com_content/articles/views/tmpl/article/default.xml to

/templates/your-template/html/com_content/article/newdefault.xml


The matching .xml file tells Joomla that the override is an Alternative Menu Item.

Once you create this, you will see the a new Menu Item Type. In the example below, I created a new Menu Item Type called New Default Single Article.

Joomla alternative menu item

To apply the Alternative Menu Item Type to an existing menu article link, open the article link and from the Menu Item Type field and click Select. Under the Articles category, you will see the new Menu Item Type you created.

To create a new article using the Alternative Menu Item Type, from the menu, click New and under the Articles category click the new Menu Item Type you created.

Joomla alternative menu item

Trackback from your site.

Comments (3)

  • Matt

    |

    Hi there,
    I’ve tried this, and it works, but the new Menu Item Type just says “New Article”. and the link seems to be the same… what am I doing wrong?

    Reply

    • Pat Fortino

      |

      I think you have to modify the name in the xml file.

      Reply

Leave a comment

Find Us On…

Find WriteNowDesign on Facebook Follow WriteNowDesign on Twitter Find WriteNowDesign on Google +

Syndicate

 Subscribe in a reader

Write Now Design, LLC BBB Business Review