Manually call Joomla Module to store as PHP variable, Allow HTML in Menu Title

This is a handy piece of code I use for whenever I need to load the output of a Joomla module as a PHP variable. One common use for this is to allow for HTML tags in menu titles. It’s also handy if you need to do string searches.

<?
// extra code to make this work
$style = -2; // set the style
$position = "column4"; // set the position of the modules to be loaded
// end of extra code
<br/>
$document = &amp;JFactory::getDocument();
$renderer = $document-&gt;loadRenderer('module');
$params = array('style'=&gt;$style);
<br/>
$contents = '';
foreach (JModuleHelper::getModules($position) as $mod) {
$contents .= $renderer-&gt;render($mod, $params);
}
<br/>
// html_entity_decode allows html from the menu title to parse normally
// otherwise, just do whatever you need to $contents
echo html_entity_decode($contents);
?&gt;

No Comments

rssComments RSS   transmitTrackBack Identifier URI

No comments. Be the first.

addLeave a comment