1

The current Joomla implementation looks like

$moduleHelper->getParams()->get('paramName'); // don't remember this one perfectly
$app->getTemplate(true)->params->get('paramName');

Is there a way I can get an array of all parameters? I need to get them in an array ready to filter based on certain specification, something like this:

(array) $moduleHelper->getParams()->get('*');
(array) $app->getTemplate(true)->params->get('*');

Please let me know. Thanks

1

I would use field groups instead of prefixes to organize fields in the form. This way no additional code is needed:

<fields name="params">
    <fields name="logo">
        <field
            name="src"
            type="media"
            default=""
            label="TPL_EXAMPLE_FIELD_LOGO_SRC_LABEL"
        />
        <field
            name="alt"
            type="text"
            default=""
            label="TPL_EXAMPLE_FIELD_LOGO_ALT_LABEL"
        />
    </fields>
    <fields name="colors">
        ...
    </fields>
</fields>

To get an object containing all values from logo group:

$params->get('logo');

Specific fields can be accessed using dot separated notation:

$params->get('logo.src');
0

I found an answer that explains the nature of the parameters and came up with a solution:

$app = Factory::getApplication();
$params = $app->getTemplate(true)->params;

$array_vars = array();
foreach(json_decode($params, true) as $k => $value) {
    if (strpos($k, 'my_setting_preffix_') !== false){
        $array_vars[$k] = $value;
    }
}

This is now exactly what I needed and the perfect solution to filter the outcome on the spot.

Cheers

3
  • 1
    json_decode() is unnecessary. $params here is a Joomla\Registry\Registry object which can be iterated.
    – Sharky
    Sep 19 at 12:15
  • In my code (templates/myTemplate/helper.php) I use $registry = new Registry(); $registry->loadString($db->loadResult()); so json_decode is required. I don't exactly know which methods from which to use (Registry / Database [getDbo]) to not need to use json_decode but I know for sure my method works and is better for my exact need.
    – thednp
    Sep 19 at 13:00
  • 1
    the $params is a Joomla\Registry\Registry object. You can get it n array format using the Joomla\Registry\Registry::toArray() function
    – Sakis
    Sep 20 at 8:49

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.