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.

Switch off the WYSIWYG Editor when inserting HTML code

The default Joomla WYSIWYG editor is great when you want to be able to format your content articles. However, the editor will strip off any HTML you try to insert. Therefore, to insert certain HTML code you need to make sure that it is switched off.

To switch off the Editor for the current user you need to logon on to the Administrator backend, click to Site > User Manager. Click on the account you logon with, and choose No WYSIWYG editor. Once this has been done, any content items you create / edit will feature pure HTML which will not get stripped off by the Editor.

Back up your Joomla website

Ok we all know you have taken all steps to prevent your website to secure your website and prevent it from being hacked. However, there are many other things which can go wrong with your Joomla website. When you have a busy site, you can never have enough backups. The following are easy ways to have a complete set of backups of your Joomla website. Did I mention that each of these comes for free?

Backup your SQL data

Backing up the content of your Joomla website is critical. You will probably be able to recreate your template if you lose it, however recreating your content is a much harder thing to do especially if you rely on several 3rd parties / visitors for your the content.

The jombackup mambot from Jomres is a small mambot which when published creates a MySql backup, compresses the file and sends it to you. The default settings are enough, no playing around with parameters is required. Just enter your email address, publish and you'll soon start getting a daily backup right to your mailbox. Try not to obliterate your mailbox too, and don't use the same email server as the host of your site, so that if you lose your site, you don't lose your email too Wink

Backup your template / media / customisations etc.

These are things which do not change often ... so a simple FTP transfer to a backup area should be sufficient. You can also choose to use a component for your backups.

A good component for backup is the JoomlaCloner backup component. This allows you to backup and restore your website easily. It also allows you to move your website from host to host.

Another non-commercial one which comes to mind is the JoomlaPack component. This creates a zipped file of all the content in your website which you can just download. This also makes it easier for you to take a backup whenever you need.

Testing Joomla site changes while site is offline

Sometimes when you need to make drastic changes to your website, you put you site offline, so that your clients get a site offline message and don't see any temporary incorrect configurations.

You as the developer / administrator of the website need to be able to see the live changes. To do this you need to open a new tab / window (and connent to your live site url) in the same browser where you are logged on as administrator doing the backend changes. If you have maintained the browser session correctly the actual current content is generated beneath the site offline message. Other users who hit your site while the site is configured as offline will only see the site offline message, and only you (due to being logged on as administrator) will be able to see the changes.

The essential thing for this to work, is that you need to ensure that you need to have two windows / tabs running under the same browser session.

Switch on the Cache

Switch on Caching to give your Joomla website an instant performance boost.


What is a cache? Wiki says:

A Cache is a collection of data duplicating original values stored elsewhere or computed earlier, where the original data is expensive to fetch (due to slow slow access time) or to compute, relative to the cost of reading the cache. In other words, a cache is a temporary storage area where frequently accessed data can be stored for rapid access. Once the data is stored in the cache, future use can be made by accessing the cached copy rather than re-fetching or recomputing the original data, so that the average access time is lower.

What does this mean in terms of Joomla? Instead of hitting your MySql database with same queries over and over again, your data is stored to a local storage (in the Joomla cache directory) and retrieved from there, instead of from the database. This means that your database will perform better, and your website will feel faster, and be able to support more simultaneous users.

Joomla 1.5

Activitating the Joomla Cache is quite straight forward. From the Global Configuration, click on System Tab, and on the right hand side there is the Cache Settings section. Click Yes on Cache Settings, and put a reasonable amount in minutes (60 minutes should be quite good for most websites). Once you press Apply, Caching will be enabled.

Joomla 1.0

The standard Joomla cache is enabled from Site > Global Configuration > System > Cache Settings (or Site > Global Configuration > Cache tab for Joomla 1.0), and mark it as enabled.

Though there are components written for caching the out of the box caching will give your website an instant boost.