Open content in a modal pop-up in Joomla
Have you ever wondered how to open an image or a Joomla page in a modal popup (one of those where the page background dims and a new page loads in front)?
To open a modal popup, you need to firstly ensure that you have the right bit of javascript loaded in the page. To do this, open your template and place the following line in the <head>
JHTML::_('behavior.modal');
This loads the Joomla code that shows the popup.
Next you need to write the link to open the content. You can do this either as a Joomla content item or just an image. Let’s do the content item first.
Open your content article and find the link you want to open in a popup:
<a href="index.php?option=com_content&view=article&id=31&Itemid=21">Link to a normal page</a>
change this to
<a href="index.php?option=com_content&id=31&tmpl=component&task=preview" class="modal">Link to a modal popup</a>
Notice we have a class added to the link called ‘modal’. This means that Joomla will find any link with that class and open it as a modal pop-up. We can take this one step further and specify the size of the popup.
<a href="index.php?option=com_content&id=31&tmpl=component&task=preview" class="modal" rel="{handler: 'iframe', size: {x: 680, y: 370}}" >Link to a modal popup with a dimension of 680px by 370px</a>
If you want to modify the template for the popup, look in your templates folder for the component.php file. This is the file we are targeting by using the tmpl=component. You can then adjust this file to suit.
If you want to open an image simply replace the href=”" with the path to the full size image.
This entry was posted on Friday, March 6th, 2009 at 11:31 am and is filed under Joomla. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.