This guide is geared towards those who wish to add a new module position to their Joomla installation. Importantly, this module position will also collapse if there is no content present; it sounds difficult, but there is very little PHP involved! This tutorial also assumes that you have a basic understanding of HTML and CSS

A guide to adding a new Joomla module position

For the sake of this tutorial, we’re going to call the new position “slider”, and here’s how we get this done.

Add the Joomla module position in template.xml
First up, look in your template directory (root/templates/YOUR_TEMPLATE/template.xml). You’ll see the following lines (or similar!)

<position>breadcrumb</position>
<position>left</position>
<position>right</position>
<position>top</position>
<position>showcase</position>
<position>slider</position>
<position>user1</position>
<position>user2</position>
<position>user3</position>
<position>user4</position>
<position>footer</position>

At this point, we’re going to add the module position to the list, as you can see from the example above.

Add the Joomla module position to index.php
Next, we’re going to delve into the index.php file. This can be found at (root/templates/YOUR_TEMPLATE/index.php)

Locate the spot where you would like Joomla to add your module position, and place the following:

<?php if ($this->countModules(‘slider’)) : ?>
<jdoc:include type=”modules” name=”slider” />
<?php endif; ?>

As easy as that! We’ll now proceed to break this down and explain what’s going on.

The first line is telling Joomla that IF a module is published and positioned at ‘slider’, it should proceed to render the content.
Line two is the method Joomla uses to add the module position where it’s needed, and defines the type of content, and the name of the module position.
Line three simply closes line 1; it tells Joomla that if the added module position hasn’t got anything published to it, it should collapse and do nothing.
You can also surround line two (the jdoc line) with a containing div in order to style it.

Adding more than one Joomla module position
In some cases you will need a position that forms multiple roles, for example on one page it may contain the slider, and on another the contact form.This simply needs an OR statement within the first line, with the module assignments for a particular page set within the module assignment section within the module manager.

<?php if ($this->countModules(‘slider or contactform’)) : ?>
<jdoc:include type=”modules” name=”slider” />
<jdoc:include type=”modules” name=”contactform” />
<?php endif; ?>

IMPORTANT NOTES
Make sure you have the module assigned for the particular page; if you go to the module manager in the Joomla admin, you can set this on Menu Assignment, located at the bottom.

You will feel a bit of a plank when the module doesn’t show up anywhere and refuses to display; it must be explicitly set within this!

Socially enable us...Tweet about this on Twitter0Share on Facebook0Share on Google+0Share on LinkedIn0Share on Reddit0Share on StumbleUpon0Pin on Pinterest0Share on Tumblr

Leave a Reply