1

I am creating a module and inside my module.php file, I created a variable named $content, which I wanted to use later as reference to get values from an associative array.

Getting the values from the array was working fine, but at the same time, I was seeing in the output of my module the value of the $content variable.

I realized that whenever I use a variable named $content inside a module, Joomla var_dumps the value of this variable;

Anyone has any clue about this behavior? Is the $content name somehow reserved - or has any other special purpose?

3

Yes, $content is used for the module rendering.

Check at /libraries/cms/modules/helper.php line 139 (function renderModule)

Around line 176

    $module->module = preg_replace('/[^A-Z0-9_\.-]/i', '', $module->module);
    $path = JPATH_BASE . '/modules/' . $module->module . '/' . $module->module . '.php';

    // Load the module
    if (file_exists($path))
    {
        $lang = JFactory::getLanguage();

        // 1.5 or Core then 1.6 3PD
        $lang->load($module->module, JPATH_BASE, null, false, true) ||
            $lang->load($module->module, dirname($path), null, false, true);

        $content = '';
        ob_start();
        include $path;
        $module->content = ob_get_contents() . $content;
        ob_end_clean();
    }

$content value is defined here, after loading the template the module output is asigned with

$module->content = ob_get_contents() . $content;
  • 1
    $module->content = ob_get_contents() . $content; - that's explain it... thanks – FFrewin Apr 30 '16 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.