Skip to the content
Documentation

Re: How to define global variables

No ratings yet

Thanks for your research.
It really logical, but I had to try a few times before it got to me:
You need to declare the variable in pagelayout.tpl to access it in templates on same or higher level than the one that sets it.

Comments (2 historical)

Written by readers of the earlier documentation sites, kept as they were.

  1. Re: Re: How to define global variables

    Guillaume ·

    This doesn't work for me, i can set the var but i cannot get the value.

    1. Re: Re: Re: How to define global variables

      Gaetano ·

      If you have trouble using scopes or namespaces, a simpler solution is to use the "persistent_variable" var:
      - it is accessed as $persistent_variable in node templates
      - it can be set directly in any template without having to be def()ined first
      - it can be set() in an included template and it will be available in the including template
      - it will even be available in another template included after the one where it is set
      - it will be available in the pagelayout via $module_result.content_info.persistent_variable
      the only drawback is that it is not easy to use in custom modules.
      To store multiple values, just make it a hashmap containing all the desired values.
      Otoh if all you need to pass around between templates are strings, you might also investigate the set-block template function, which takes scope and namespace params. It works better than set.