Including Modules as Part of an Articles' Content
One common question we have been getting in relation to our last blog post, Writing a Simple Joomla Module, is how we included the module as part of the article without just placing it into a module space specified in the template and appending it to the article itself. Joomla 1.5 has easily simplified this task by allowing the module system to declare custom spaces and have these be loaded through an included plugin. This may seem a little confusing at first but we hope we can clear it up below!
Before we get started, we need to remember that plugins are extensions to the Joomla framework that can directly affect the content of an article, or be called from within an article using a standard definition, much like any html of php code. So for example:
Might start flashing the above text if it was included as part of an articles contents. There are thousands of plugins and they can preform many interesting functions. For example, the way we wrap certain code snippets in an easy to read formats is the Code Citation plugin. In a similar vain we will be calling the module position that our modules are in from a plugin in an article, but lets get to the custom module position first.
From versions less than Joomla 1.5, you may be used to the fact that module positions are a locked in list defined in the template. However, in 1.5 you can actually edit the module position right in the module settings, assigning it a totally arbitrary position. Just highlight the module position text and type in any arbitrary position you like. For example, in the below image we used GBP_BlogPost to give our Google Book Preview a unique position on our website.
Next we need to make sure that the plugin to load modules is activated. To look at plugins follow the top menu from Extensions -> Plugin Manager and you should see a plugin called Content - Load Module somewhere on the first or second page. Make sure the green check mark is there, else click on the red cross to turn it on.
One last step is to make sure that the plugin is configures properly. Click on the plugin itself and much like a module, you will see a space for plugin parameters. Now you can choose whatever you want to wrap your modules with but it is heavily recommended that you set the Style parameter to: No Wrapping - Raw Output. This way you minimize any design clashes between modules and your website.
Once the plugin is activated, all you need to do is load the module position from within your article. The format for invoking the plugin is:
So for our example, all we need to include in our blog article is:
And there you go, couldn't be easier.