The template should dynamically display the Joomla content from components, modules and plugins at different positions. How this goal is achieved in Joomla is the topic of this chapter. So: How are module positions integrated in the Joomla template.

For impatient people: Take a look at the changed programme code in the Diff-Ansicht[^] and copy these changes into your development version.

Step by step

We will proceed step by step. In this part we add the module positions so that Joomla displays content dynamically. We will take care of the design in the next part.

New files

In this chapter only files have been changed and no new ones have been added.

Changed files


So far we have more or less a static website. In this part, we add content dynamically using module positions.


I already mentioned it in the previous part: The file component.php displays only main content. This is the content of type component. Navigation and content in sidebars are omitted. For testing we had created this file. So far it contained only the static text Component. Now we extend it by its actual task. A minimal structure looks like this.


<!DOCTYPE html>
<html lang="de">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<jdoc:include type="head" />
	<jdoc:include type="message" />
	<jdoc:include type="component" />

The main new entry is <jdoc:include type="component" />. The command inserts the main content of the current page.

In addition, we use <jdoc:include type="message" /> and <jdoc:include type="head" />. <jdoc:include type="message" /> displays system and error messages that occurred during the request.

Are you wondering what system and error messages are exactly? In Joomla they are generated by $this->setMessage(Text::sprintf('MESSAGE_TEXT', $id), 'error'); in an object of type BaseController[^libraries/src/MVC/Controller/BaseController.php#L1066]. In the file administrator/components/com_content/src/Controller/DisplayController.php you will find an example[^administrator/components/com_content/src/controller/displaycontroller.php#l55]. This outputs the text You are not permitted to use that link to directly access that page. in the frontend. This is exactly where <jdoc:include type="message" /> is inserted in the template.

<jdoc:include type="head" /> loads content that requires extensions and includes them via special commands. These are mainly scripts and styles.

<jdoc:include type="head" />, <jdoc:include type="message" /> and <jdoc:include type="component" /> should appear only once in the <body> element of the template. More information about the commands can be found in the Joomla documentation[^].


You already know it: The file index.php is the heart of the template. It makes sure that everything works together. In the previous chapter we had not integrated Joomla's own content. I will make up for this here. A minimal structure, which inserts the Joomla content, looks like this.


 	<meta name="viewport" content="width=device-width, initial-scale=1.0">

	Hallo Joomla
		     <jdoc:include type="modules" name="topbar" />

		     <jdoc:include type="modules" name="below-topbar" />

					<jdoc:include type="modules" name="menu" />
				<jdoc:include type="modules" name="search" />

		<jdoc:include type="modules" name="banner" />

		<jdoc:include type="modules" name="top-a" />

		<jdoc:include type="modules" name="top-b" />

		<jdoc:include type="modules" name="sidebar-left" />

		<jdoc:include type="modules" name="breadcrumbs" />
		<jdoc:include type="modules" name="main-top" />
		<jdoc:include type="message" />
		<jdoc:include type="component" />
		<jdoc:include type="modules" name="main-bottom" />

		<jdoc:include type="modules" name="sidebar-right" />

		<jdoc:include type="modules" name="bottom-a" />

		<jdoc:include type="modules" name="bottom-b" />

		<jdoc:include type="modules" name="footer" />

 <jdoc:include type="modules" name="debug" />


Inside the header area Joomla templates load header information with <jdoc: include type="head" /> via Joomla API. We already use this above in the component.php file. The jdoc:include command inserts the necessary header information. This way you are on the safe side. I don`t use this command in the index.php at the moment, because I want to show, that you can also choose yourself, what you need.

We can find the jdoc:include command in other places in index.php. For example, we see <jdoc:include type="message" />, so the system messages work. Whenever Joomla has something to tell the website visitor, this line will display it on the screen. For example, when sending an email through a contact form, you will see the message "Your message was sent successfully".

Another element to discuss is <jdoc:include type="component" />. This element inserts the main content into the site.

The last element worth mentioning is <jdoc:include type="modules" />. As the name suggests, this is used to include modules.

So, enough explained. All contents are integrated via module Positions. They are not displayed nicely so far. Don't be scared if you open this version in your browser later. You will see all content in unstyled form at the moment.

It may be important to you that a module position is only inserted if a module is published under it, because this makes it easier to prevent the unnecessary setting of HTML elements for a wrapper. How to achieve this is a topic of the next chapter. Or you want to make it optional in the template which module position is used. For example, it is important to you that a sidebar can be completely deactivated.You can achieve this with the help of parameters, which are the subject of the next but one chapter.


Via the language files it is possible to describe the positions exactly. Note the line TPL_FACILE_POSITION_TOP-A="Area under banner". TOP-A does not mean much to a user. He understands Area under banner.

Create Joomla Template - Name Module Positions


 FACILE="Facile - Site template"
TPL_FACILE_POSITION_TOP-A="Area under banner"
TPL_FACILE_POSITION_TOP-B="Area above the content"

In the file templateDetails.xml the module positions are inserted to be selectable as position when creating a module. So a module is includeable via the command jdoc:include in the index.php.




Changed files

Only files have been added in this section.

Test your Joomla template

  1. install your template in Joomla version 4 to test it:

Copy the files in the templates folder to the templates folder of your Joomla 4 installation.

A new installation is not necessary. Continue using the ones from the previous part.

  1. install the sample data, so that you have the same prerequisites as I have.

Create Joomla Template - Install sample files

  1. test now, if the sample files are displayed correctly. Activate the template style Cassiopei and call the URL joomla-cms4/index.php. How you change a template style, I had shown in the previous chapter with a picture. Your view should be like in the following picture.

Create Joomla Template - View in Cassiopeia

  1. next test if our template Facile works without errors. Activate the Template Style Facile and call the URL joomla-cms4/index.php again. Your view should be like in the following picture.

Create Joomla Template - View Facil ungestyled

You can view the module positions in the frontend. Activate the view in the global configuration in the backend and call the URL joomla-cms4/index.php?tp=1. The appendage ?tp=1 is crucial.

Create Joomla Template - Show Module Positions - Backend

Create Joomla Template - Show Module Positions - Frontend

This does not look inviting. I agree with you there. So next we pep up the template with CSS and JavaScipt and adjust the default views of Joomla.