Retrieving Joomla 1.5 Component, Module, Plugin and Template Parameters

Written by khawaib

Topics: Joomla! 1.5

In Joomla 1.5 parameters enable users to configure settings that later can be used in code of extensions and templates. Following are the ways that can help a developer to access these parameters.

Component Parameters

From inside a Component:

$componentParams = &JComponentHelper::getParams('com_example');
$param = $componentParams->get('parameter_name', 'default_value');

From outside a Component:

$componentParams = &JComponentHelper::getParams('com_example');
$param = $componentParams->get('parameter_name', 'default_value');

Module Parameters

From inside a Module:

$param = $params->get('parameter_name', 'default_value');

From outside a Module:

$module = &JModuleHelper::getModule('module_example');
$moduleParams = new JParameter($module->params);
$param = $moduleParams->get('parameter_name', 'default_value');

Plugin Parameters

From inside a Plugin:

$param = $this->params->get('parameter_name', 'default_value');

From outside a Plugin:

$plugin = &JPluginHelper::getPlugin('plugin_example');
$pluginParams = new JParameter($plugin->params);
$param = $pluginParams->get('parameter_name', 'default_value');

Template Parameters

From inside a Template:

$param = $this->params->get('parameter_name');

From outside a Template:

$mainframe = &JFactory::getApplication();
$params = $mainframe->getParams(JFile::read(JURI::root().'/templates/template_name/params.ini'));
$param = $params->get('parameter_name', 'default_value');

From out Joomla Framework:

$paramsFile = dirname(__FILE__) . '/../params.ini'; // Get params.ini

// check if file exists
if(file_exists($paramsFile)) {
    $iniString = file_get_contents($paramsFile); // get ini file contents
    // Escape double quotes in values and then double-quote all values
    $iniQuoted = preg_replace('/=(.*)\\n/', "=\"$1\"\n", addcslashes($iniString, '"'));
    $iniParsed = parse_ini_string($iniQuoted);
} else {
    $iniParsed = '';
$params = (!empty($iniParsed)) ? $iniParsed : array();
$param = $params['paramName'];

Leave a Comment Here's Your Chance to Be Heard!

You must be logged in to post a comment.