1

I'm trying to get a variable from my module to my template but its not working.

In my modules xml I defined:

<fields name="params">
    <fieldset name="basic">
        <field
            name="imageUrl1"
            type="text"
        >
        </field>
        <field
            name="imageUrl2"
            type="hidden"
        >
        </field>
        ...

In my modules tmpl/default.php I do:

$params->set('imageUrl1', $imageSrc)
$params->set('imageUrl2', $imageSrc2)
...

and later in the same file I do:

echo "<p>imageUrl1: {$params->get('imageUrl1')}</p>";

and it shows the correct image link. Everything is fine so far. But then I try to get it from my templates php file and it's not working.

In my index.php I do:

$module = JModuleHelper::getModule('mod_mymodule');
$moduleParams = new JRegistry($module->params);

if ($moduleParams) {
    $moduleImage1 = 'url("/' . $newsParams->get('imageUrl1') . '")';
    $test = $newsParams->get('otherParam');
}

echo ":root {
--moduleImage1: {$moduleImage1};
--test: {$test};
}";

The thing is: The test variable thats set in the admin module menu is coming through fine but my image URL that I want to have is not going through. The printout is just: --moduleImage1: url("/");

So has anyone any idea how to get this to work? Or even a workaround so I can have the same result?

3
  • This will not work. Template is parsed before modules are rendered. What are you trying to do here?
    – Sharky
    Jun 19 at 19:10
  • @Sharky I wanna transfer a variable from a module to the template. Jun 19 at 19:50
  • But why? For what purpose?
    – Sharky
    Jun 19 at 20:31

0

Your Answer

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

Browse other questions tagged or ask your own question.