How to add a module to your offline page

Posted by: webmaster in TutorialOffline pageModulesJoomla 1.5 on  

I've received an interesting question which I want to share. Someone wanted to know if it is possible to add the Ulti Counter module to his offline page. This way he can show a countdown until his new site gets online. Yes, this is possible and the Joomla Framework API makes it quit easy.

 

If you haven't already done so, you need to create a custom Joomla offline page first. This was already covered in a previous blog post:  How to change the default Joomla offline page.

 

To add a module like the Ulti Counter module to your offline page, just add this piece of code somewhere in the body tag:

 

<?php

$module =& JModuleHelper::getModule('mod_ulti_counter');
$document = JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$contents = $renderer->render($module);
echo $contents;

?>

 

The first line is the line which select the module. The other lines are there to render the module.  To get the right parameter in the first line, you can check the Module Manager of your Joomla back-end.  The name of the module, is what you find in the column 'Type' without the 'mod_'. So in this case it's 'ulti_counter', but you can do the same for any other module you'd like to add to your page.

 

That first line will select the first module instance with that name. But what if you have 2 instances of the same module? Mayby you have a second Counter on your site. In this case you can add a second parameter to this function, to make sure the right instance of the module is selected. This second parameter is the title of your module. Suppose you have 2 instances and you give them as title 'Counter1' and 'Counter2', then you can select the second Ulti Counter instance like this:

$module =& JModuleHelper::getModule('ulti_counter', 'Counter2');

 

Trackback(0)
Comments (0)Add Comment

Write comment

security code
Write the displayed characters


busy