Joomla 4.x-Tutorial - Entwicklung von Erweiterungen - Template - Module Positions

Modify this post

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

For the impatient

Take a look at the changed programme code in the and incorporate 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.

In the following overview, the newly added files are marked with a background and the changed ones are outlined.

Overview of the files edited in this chapter

New files

The only changes made in this section are.

Changed files


So far, we have 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. <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 here, because I want to choose what I need in the main view itself.

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 included. They are not displayed nicely yet. Don't be scared if you open this version in your browser later. You will see all content in unstyled form at the moment.


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.

Modify this post