Do you know that you can display Joomla modules inside components? This is possible with only 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 Joomla's com_articles component for this example. However, this approach works for any Joomla component.
Step #1. Create a template override
Let's create a template override to place our customizations safely.
- Go to Extensions
- Templates
- Templates (child menu)
- Your template details and files
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/
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', ''); ?>
- Click "Save & 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.
Step #4. Check the end result
Preview one of your full articles in the frontend of your site. The module should be visible somewhere inside the article layout.
Have problems showing modules inside articles?
- Go to Extensions > Plugins.
- Make sure the plugin Content - Load modules is enabled.