MyBB Community Forums

Full Version: Variable scope for template vars?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a {$template_variable} which works in the showthread template, and not in the header. In general, how / where are template variables created, and their 'scope' set?
  • If you were 'creating a new 'template variable' to go in the header what would that section of code look like?

Thank you.
Depends entirely on where the particular template is being evaluated. Most of them have access to the global scope, but some of them are within functions with access to only the restricted functions scope. For your own custom variables, they'll have to be global and initialized before MyBB evaluates the template (which it unfortunately does early on for several templates, so if in doubt use global_start hook).

If a template does not have access to global variables, you'll have to go via $lang or $mybb or some such.
OK, thanks frostschutz