Special Sale! Get all our extensions, templates and training for under $100!  Sale ends in
Joomlashack

How to Add a Joomla Module Position Inside Any Component

Joomla Tip: Add New Module Positions Inside a Component

Do you know that you can display modules inside components? This is possible with a single line of PHP code.

In this tutorial, I'm going to show you how to display a module inside any component.

We will use the articles component for this example. However, this approach works for any component.

Step #1. Create a template override

Let's create a template override to place our customizations safely.

  1. Go to Extensions
  2. Templates
  3. Templates (child menu)
  4. Your template details and files

6

We are about to create a template override for single articles.

  • Now go to the Create overrides tab.
  • In the "Components" column, click on com_content > article. A set of files will be generated in the folder /templates/your-template/html/com_content/article/

1

Step #2. Edit the template override

  • Go to the Editor tab
  • Find the file default.php inside the /com_content/article/ folder
  • Add the custom php code below where position-name means the name of your custom module position:
    <?php echo JHtml::_('content.prepare', '{loadposition position-name}'); ?>

2

  • Click Save and close when you're done

Step #3. Create a new module

Let's test our custom module position.

  • Go to Extensions > Modules > Add new.
  • Choose the module type you want. In our example, we're going use a Custom HTML module.
  • Type the new module position in the Position parameter, and press the Enter key. In this case, we're using position-name.
  • Under "Menu Assignment", make sure the module is enabled for all the pages.
  • Save and close the module.

3

Step #4. End result

Preview one of your full articles in the frontend of your site. The module should be visible somewhere inside the article layout.

4

Have problems showing modules inside articles?

  • Go to Extensions > Plugins.
  • Make sure the plugin Content - Load modules is enabled.

5


About the author

Valentín creates beautiful designs from amongst the tequila plants of Jalisco, Mexico. You can see Valentín's design work all over this site and you can often find him helping members in support.

 

 

Since 2005, Joomlashack has been a leading supplier of free and commercial Joomla templates, Joomla extensions, and Joomla Training.
Joomlashack.com is not affiliated with or endorsed by the Joomla! Project or Open Source Matters.
The Joomla! name and logo is used under a limited license granted by Open Source Matters the trademark holder in the United States and other countries.