To add some common ground. I need to transfer 3 variables from a module to my template when the sites loading. In my module I get 3 links to specific images and they need to be included in the template. So I tried to do in my module:

$session = Factory::getSession();
$session->set('image1', $value);

and in my index.php:

$session = Factory::getSession();
$variable = $session->get('image1');

The issue is that this only works if I refresh my page. I understand that the template is loaded first and the module is loaded second so the template reads the variable before it is set. The question is: Is there away around this? How can I accomplish what I want to?

  • What are you trying to accomplish?
    – Sharky
    Commented Sep 20, 2022 at 6:07
  • @Sharky Like it said in the text: I need to get some variables (text) from a module to the template. I just need to transfer some variables nothing more but it seems nearly impossible. The other way around (from module to template) its easy and straight forward. Commented Sep 20, 2022 at 20:40
  • Yes, but for what purpose? Without knowing it's hard to come up with a solution. You already know the current approach doesn't work. Maybe the logic should be moved to a plugin or maybe you could use client-side (Javascript) solution. It is also possible to programmatically retrieve modules and render them without jdoc tags in the template, although it's not a good approach either.
    – Sharky
    Commented Sep 20, 2022 at 20:59
  • @Sharky I have a "News" module that retrieves the last 3 articles with the tag "news". In order to render the article images correctly in my styling they need to be included as a background-image in my template because I handle all css in my template. Thats why I need to get 3 varaibles from my module to my template. I mean there has to be some way without breaking my coding structure or using obscure workarounds.... Commented Sep 21, 2022 at 20:32

1 Answer 1


For this exact issue the solution was to avoid the things that are not working. So instead of trying to get the variable from the module to the template in my php I created a html variable "--myvar" as a placeholder in my template and used:

echo ":root { --myvar: {$variableITriedToGetAcross}; }";

and that proved to be effective because now it works fine but I had to compromise in some way. The thing is the css is loaded after all the modules and templates so the template gets the value trough the css after loading.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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