Layout overrides in Joomla

From Joomla! Documentation

This page is a translated version of the page Layout Overrides in Joomla and the translation is 29% complete.

Other languages:
Deutsch • ‎English • ‎español • ‎français • ‎italiano • ‎Nederlands • ‎中文(中国大陆)‎
This Article Needs Your Help

This article is tagged because it NEEDS REVIEW. You can help the Joomla! Documentation Wiki by contributing to it.
More pages that need help similar to this one are here. NOTE-If you feel the need is satistified, please remove this notice.

Split Page into Specific Joomla! Versions - J2.5 and 3.x

It has been suggested that this article or section be split into specific version Namespaces. (Discuss). If version split is not obvious, please allow split request to remain for 1 week pending discussions. Proposed since 51 days ago.

Introduction to Alternative Layout Feature in Versions 2.5+

Joomla! 1.5 introduceerde het concept van overriding core layouts met behulp van het template override systeem. Joomla! versie 2.5 introduceerde een reeks functies die de sitebeheerder meer controle geven over de weergave van artikelen, contacten, nieuwsfeeds en webkoppelingen. Er zijn vijf soorten alternatieve layouts:

  1. Module
  2. Component
  3. Category
  4. Menu Item
  5. JLayouts

Alternative layouts work in a similar fashion to the template override feature but allow you more options and control. Each type is discussed below.

Module Alternative Layouts

Creating an alternative layout for a module is similar to creating a template override for a module. In both cases, you create a folder called templates/<your template>/html/<module name>. For example, the folder for a "mod_login" template override or alternative layout for the beez5 template would be templates/beez5/html/mod_login/.

There are two important differences between a template override and an alternative layout. The first is the file name. For the template override, you would call the file default.php to match the core file name. For an alternative layout, you use a different name. The only rule is that the file name should not have any underscores in it. This allows you to have complex layouts that include multiple files. The initial file to be called is named without underscores and any other files that are called from this initial file will have underscores in the name. For example, you could have the initial file called mynewlogin.php which calls mynewlogin_1.php.

The second important difference is that, unlike template override files which are called automatically whenever the module is displayed using the template with the override, an alternative layout file is only called if you select it as a parameter in the Module Manager. In version 2.5 and later, there is a new parameter under Advanced Options called Alternative Layout, as shown below.

Screenshot override tutorial 20110107-01-en.png

This parameter will list any files (without underscores) that you have placed in the template folder for this module. You can also translate the file name using the template's system language file. For example, if you add the line


to the file en-GB.tpl_beez5.sys.ini, it will translate the file name nologin.php to "Alt Login Layout".

It is important to understand that if specified in the Module Manager screen, an alternative layout file for a module will be used for that module regardless of what template is used to display the page where the module is shown. It is therefore the administrator's responsibility to make sure that the layout file will work as desired in any templates where this module may be shown.

Plugin Alternative Layouts (Overriding a Plugin)

Yes, it's possible to override plugin outputs. It's very useful, especially for content plugins. However you can only do it if the plugin is ready to allow overrides.

A Tip!

Joomla provides a mechanism to override a plugin but this feature is not supported by all the plugins

Right now the only plugin in Joomla 3.x core that allow overrides is the Pagenavigation Content plugin that shows previous/next article links in article view of content component. There may be other plugins from third party developers allowing it and more core plugins will be overridable in the future.

You will know when a plugin is overridable because has a /tmpl/ folder in it. See: (note for developers: the plugin uses JPluginHelper::getLayoutPath() )

Plugin Override example

To override the output of Pagenavigation content plugin in "beez3" template, create a folder named templates/beez3/html/plg_content_pagenavigation/ and copy the original layout file (plugins/content/pagenavigation/tmpl/default.php) to this new folder.

Now you can change this layout file to override plugin output.

Is important to note that to build the override layout you need to create it in this path:


example: templates/beez3/html/plg_content_pagenavigation/

Where PLUGIN-GROUP is the group to which the plugin belongs. (It is the name of the first folder where the plugin is located. See: Read more about Event groups at Plugin/Events)

Component Alternative Layouts

Component alternative layouts work similarly to module layouts discussed above. Again, a file is placed in the same folder where you place a template override file. For example, to create an alternative layout for an article for the template "beez5", you would put a file in the folder templates/beez5/html/com_content/article/. As with module layouts, the file must not be named the same as the core file and must not include underscores in the name. Additionally, there should not be an XML file of the same name in this folder. (We'll discuss XML files below under Menu Item Alternative Layouts.)

You can set a global value for component layouts in the Options window of the component. For example, in the Article Manager Options window, there is a parameter for Alternative Layout as shown below:

Screenshot override tutorial 20110107-02-en.png

This will create a global value that individual components (articles, contacts, news feeds and Web links) can inherit from.

As with module layouts, the component layouts are shown as parameter options in the individual component edit screen. For example, for an article, the parameter shows in the Article Options group as shown below.

Screenshot override tutorial 20110107-03-en.png

As with other parameters, the Use Global setting will use the setting from the Options parameter. The From Component's Default setting will use the component's default layout. Alternative layouts that you have created for different templates are shown under each template heading.

File names may be translated. The line below:


will translate a file called "mylayout.php" as "Title Only No XML".

You can have more than one file for a layout. The initial file must be named without underscores and any additional files must have underscores.

Component alternative layouts may be used with articles, contacts, or news feeds. Web links don't have a single-component layout so no alternative layout is available for Web links.

Component alternative layouts are only used when two conditions are met: (1) they are specified in the component parameters; and (2) there is no menu item for this specific component. For example, if you have one or more menu items of type "Single Article" set up for a given article, then the alternative layout for that article will not be used. Instead, the layout specified in the menu item will be used. This is consistent with the general way that component parameters work, where the most specific (in this case a single-article menu item) overrides the less specific (in this case, the article parameters).

Category Alternative Layouts

Category alternative layouts work identically to component layouts. The rules for specifying layout files are the same. The only difference is that the folder is the category folder, not the component folder. For example, a contact category alternative layout for beez5 would go in the folder templates/beez5/html/com_contact/category.

You can set category layouts globally, in the Options screen of each component. Below is an example from the Contact Manager Options screen:

Screenshot override tutorial 20110107-04-en.png

Category alternative layouts show up when you add or edit a category in the Category Manager under the Basic Options as shown below.

Screenshot override tutorial 20110107-05-en.png

Category alternative layouts may be used for articles, contacts, news feeds and Web links.

As with component layouts, category layouts only will show if (1) they are specified for the category in the global or category parameters and (2) there is no menu item specifically for this category (for example, List Contacts in a Category, List News feeds in a Category, List Web links in a Category, Category List, Category Blog).

If there is a menu item set up for this specific category, that layout will be used instead of the alternative category layout.

Drill Down to Blog or List

For articles, we have two core layouts available: Blog and List. Both of these options show under the "From Component" heading in the layout parameters for article category. So, like other layout options, you can now select Blog or List for categories either globally (in the Article Manager Options, shown below), or when editing a single article category.

Screenshot override tutorial 20110107-06-en.png

This means that, like other layout options, you can control whether article category links drill down to blog or list layouts. It is important to understand that, like other layout parameters, this option will only take effect when there is no single-category menu item for the category.

Alternative Menu Items

Alternative Menu Items have one important difference with the others. To create a menu item alternative layout, you must include an XML file whose name matches the initial layout file. For example, to create an alternative menu item called "myarticle" for an article in the beez5 template, you would create two files in the templates/beez5/html/com_content/article folder called myarticle.php and myarticle.xml. If you wanted to include more layout files, you would add these files with underscores in the file names.

The XML file uses the same format as the core Menu Item XML files. This allows you not only to create a customized layout for this menu item but also allows you to create customized parameters. For example, you could hide some parameters or add new parameters.

Alternative Menu Items show up when you select a menu item type in the Menu Manager as shown below.

Screenshot override tutorial 20110107-07-en.png

Alternative Menu Items are used and work the same way as standard menu items. Since they are already based on customized layouts, template overrides do not apply to alternative menu items.

As indicated above, menu item layouts take priority over component or category alternative layouts.

Translation of alternative menu items is done with the following tags in the XML files. The format is "TPL_"<template name>_<component>_<view>_<menu item name>_<tag type>. For example, these lines below will translate the title, option, and description for an alternative menu item called "catmenuitem".

TPL_BEEZ5_COM_CONTENT_CATEGORY_VIEW_CATMENUITEM_DESC="Description for beez5 custom category layout."

These strings have to be added to language/en-GB/en-GB.tpl_beez5.sys.ini

The catmenuitem.xml would start with:

<?xml version="1.0" encoding="utf-8"?>

Controlling the Template for Alternative Menu Items

As discussed above, the presence of an XML file makes an alternative layout a menu item. The format of the XML file is the same as the format for core menu item XML files. With this XML file, you can add the parameters you wish to include for this menu item. They can be the same as one of the core menu items, or you can omit core parameters or add new ones. Note that if you add new parameters, these can be used in the layout file but will not be used in the core model or view files.

It is also possible to override parameter settings for core parameters. One example of this is to control which templates an alternative menu item layout can be displayed with. In some cases, you may want to allow a custom menu item to be displayed with any template for the site. In other cases, you may wish to limit that menu item's layout to one specific template. In this situation, you would just add the following parameter to the menu item's XML file:


This will override the core template_style_id parameter. Setting the template equal to "beez5" in this case will limit the user to only selecting template styles for the "beez5" template.

JLayout Micro-Layout Overrides

JLayouts is een krachtige functie van Joomla! JLayouts kunnen losjes worden gedefinieerd als micro-layouts. Het zijn de micro-indelingen voor afzonderlijke elementen van Joomla! pagina's. De knop Meer lezen, de introductieafbeelding, de volledige afbeelding zijn bijvoorbeeld allemaal voorbeelden van elementen die worden bestuurd via een eigen JLayout.

Als we dieper ingaan op de weergave Categorie blogopmaak, vindt u de code om de titel van het artikel, een introductieafbeelding, de introductietekst en verschillende andere relevante delen van de pagina aan te roepen. Zo ziet het eruit wanneer u een element met JLayout aanroept.

<?php echo JLayoutHelper::render('joomla.content.blog_style_default_item_title', $this->item); ?>

Dit specifieke stukje code plaatst de titel van het artikel in de Joomla! Categorie blog.

Om je te helpen de locatie van het bestand voor dit specifieke element te begrijpen, kan het helpen te weten dat er een naamgevingsconventie in het spel is. Kijken naarjoomla.content.blog_style_default_item_title de stippen kunnen worden vervangen door /'s om de mapstructuur te begrijpen. Alle JLayouts zijn aanvankelijk te vinden in JOOMLAROOT /layouts. Met behulp van de naamgevingsconventie kunnen we zien dat dit bestand zich bevindt in JOOMLAROOT/layouts/joomla/content/blog_style_default_item_title.php.

Laten we een voorbeeld doornemen. Voor dit voorbeeld verplaatsen we de introductieafbeelding boven de titel, u kunt er ook wat extra structuur omheen toevoegen als u dat wilt.

U moet JLayout-bestanden niet rechtstreeks bewerken, omdat wijzigingen tijdens een kernupgrade zouden worden overschreven. De juiste manier om de JLayout bij te werken, is door het element te vinden dat u wilt overschrijven (zoals intro_image) en het bestand naar uw sjabloon te kopiëren. Kopieer vervolgens de mapstructuur van het element dat u wilt overschrijven dat bestaat in de lay-outmap in de Joomla! bovenliggende map, bijv.templates/YOUR_TEMPLATE/html/. U wilt alleen de bestanden kopiëren die u nodig heeft om bloat op de site te voorkomen en de kans op het veroorzaken van een probleem te minimaliseren.

Een voorbeeld van de intro_afbeelding zou oorspronkelijk te vinden zijn in: JOOMLAROOT/layouts/joomla/content/intro_image.php

Het gekopieerde bestand zou zijn:templates/YOUR_TEMPLATE/html/layouts/joomla/content/intro_image.php

As a simple example let's add a responsive image class to the intro image. First of all, we open our copied JLayout file, which we just placed in templates/YOUR_TEMPLATE/html/layouts/joomla/content/intro_image.php.

Zoek naar de volgende regel

<div class="pull-<?php echo htmlspecialchars($imgfloat); ?> item-image">

Laten we onze responsive image class toevoegenimg-responsive aan de bestaande classes.

<div class="pull-<?php echo htmlspecialchars($imgfloat); ?> item-image img-responsive">

Ok, we hebben onze class toegevoegd. Laten we het bestand opslaan en sluiten. Zorg ervoor dat het wordt geüpload naar onze website. Als we nu de pagina vernieuwen, zien we de klasse img-responsive op onze introductieafbeeldingen. Je hebt zojuist een JLayout gebruikt, denk aan alle andere geweldige dingen die je met JLayouts zou kunnen doen?

Creating a new JLayout that only appears on some pages

Je kan ook nieuwe JLayout bestanden maken. Ze hoeven niet gebaseerd te zijn op bestaande elementen. Voeg ze eenvoudig toe aan deYOUR_TEMPLATE/html/layouts/ directory zoals hierboven en Joomla! zal ze kunnen vinden. Vervolgens moet u in uw code naar de nieuwe JLayout verwijzen. Voor de eenvoud heb ik in dit voorbeeld een bestaand element gedupliceerd en mijn eigen versie gemaakt.

Ik zal beginnen met een standaard HTML template override for the Blog layout (niet een JLayout override). U kunt verderop op deze pagina lezen hoe u dit kunt doen. Door een sjabloon te negeren, worden enkele bestanden toegevoegd aan mijn templates/YOUR_TEMPLATE/html map. Ik maak een nieuwe JLayout die ik ' alleen in mijn blogweergave wil gebruiken. Als ik eenvoudigweg de JLayout voor intro_image bewerkte, zou dit al mijn intro_images beïnvloeden, maar ik wil alleen mijn Category Blog View intro_images wijzigen.

Het bestand dat ik wil gebruiken istemplates/YOUR_TEMPLATE/html/com_content/category/blog_item.php. In dat bestand vind ik de regel<?php echo JLayoutHelper::render('joomla.content.intro_image', $this->item); ?> die een JLayout-element aanroept. Die specifieke code is voor het element intro_image.

Omwille van de eenvoud heb ik het bestand gekopieerdJOOMLAROOT/layouts/joomla/content/intro_image.php. Ien geplaatst in templates/YOUR_TEMPLATE/html/layouts/joomla/content/ en een andere naam gegeven intro_image_blog.php.

Nu open ik mijn template override bestand templates/YOUR_TEMPLATE/html/com_content/category/blog_item.php. Ik vind de verwijzing naar<?php echo JLayoutHelper::render('joomla.content.intro_image', $this->item); ?>, Ik verwijder het, Ik verplaats de JLayout boven de titel en ik gebruik mijn eigen JLayout die ik zojuist heb gemaakt templates/YOUR_TEMPLATE/html/layouts/joomla/content/intro_image_blog.php .

Nu wordt mijn nieuwe JLayout gebruikt en deze is boven de titel geplaatst. Ik kan nu verdere wijzigingen aanbrengen, zoals indien nodig een responsieve beeldklasse toevoegen en wijzigingen worden alleen weergegeven in de weergave Categorieblog.

Further Reading

You can find further reading here