Saturday, February 7, 2009

Load a module within an article

Did you know it is possible to actually load a module directly in your content? E.g. We want to load our Featured Articles module in an article rather than in a module position. We can do this using the Load Module Position defaultJoomla mambot.

Joomla 1.5

In Joomla 1.5, there is a default plugin which does this. You can call any module position in a content item with the following code:

{loadposition user4}

Remember, you have to enable the loadmodule plugin from the Plugin Manager.

Joomla 1.0

Edit: See bottom for a new way of doing this, using a 3rd party module though

The Load Module positions mambot allows us to load any mambot position as a mambot. Therefore to load the module in a content article we can use the following workaround.

  • From the Template Positions (Site > Template Manager > User Positions), choose a module position which is not used in your template e.g. user8. If all your positions are used in the template, create a new position.

Create a new template position

  • Assign the module you want to display to the position you have chosen above - Modules > Site Modules. Make sure that Menu Item links is set to All (otherwise the position will not load)

Setup the module with all necessary parameters

  • In your content item enter the following: { mosloadposition user8 } (be sure to remove extra spaces before mosloadposition and after user8, spaces were added intentionally in this example). This will be replaced by the content of the module(s) assigned to that position.

Insert the mambot text into your content

Below is an example of usage of this module. We are loading the Featured Articles Module in the content of this article:

Another good example of usage of this module is this. You want to create an advert (or affiliate link), but instead of copying and pasting the code, you want to be able to replicate this advert at will in your content items. Therefore you use the mod_html module to create the advert you need. Now, each time you want to display this advert, you just insert the { mosloadposition xxxx } (be sure to remove extra spaces before mosloadpostion and after xxxx, spaces were added intentionally in this example) in the content. The good thing about this is that if you want to change the advert, you only need to change this in the module rather than in every content item.

Edit: There is a cool module which allows you to avoid all the hassle above. Amongst various functions it allows you to use code as follows to do the above in a much simpler manner:

{mosmodule modulename} and the module is immediately loaded.

No comments:

Post a Comment