Page 1 of 1

Custom module bug: Don't use any variable named $content.

Posted: Tue May 28, 2013 5:05 pm
by MonkeyT
There is a variable scope error that is built into Joomla's custom module mechanism.
It really is a silly mistake, and could probably be fixed in a heartbeat by anyone familiar with the Joomla CMS core.

Inside a custom module, if you use a variable with the name "content", Joomla will dump that variable's value to the screen once the module is rendered.

Proof? Add this line to the main file of your module:

$content = "Malarkey";

When the module renders to the screen, Joomla will add the word "Malarkey" to the end of the text. I do not know where this rendering occurs within Joomla's core code, but if you avoid that variable name, you'll never see it happen.

I hope this helps.