MyBB Community Forums

Full Version: Variables
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
{$additionalusergroup}

I noticed variables like the above when I use a plugin. Where are those defined?
Most likely inside the file (or files) that came with the plugin. Can't give you a definitive answer for where '$additionalusergroup' is defined without knowing exactly which plugin you're using.
(2012-12-16, 09:25 PM)Beardy Wrote: [ -> ]Most likely inside the file (or files) that came with the plugin. Can't give you a definitive answer for where '$additionalusergroup' is defined without knowing exactly which plugin you're using.

I just meant in general and was using that as an example. Any specific file you maybe referring to?
(2012-12-16, 09:42 PM)dalawh Wrote: [ -> ]I just meant in general and was using that as an example. Any specific file you maybe referring to?

Template variables are usually defined right before a template is loaded in, they're not defined in one specific place. In terms of plugins, they're usually defined inside a hooked function and made global, so the template that is loaded after the function runs is able to access those variables.

A tip to finding out what data certain template variables hold is to use a text editor that can search across multiple files (Notepad++ is fairly useful, though I prefer Netbeans' search) and search the mybb files for '$templates->get("___")', replacing the underlines with the template you're viewing, and then browse up a few lines until you find the variable you're looking for. Or just search for the name of the variable, though in certain cases this may bring up quite a few results (possibly in the same file) and it may be difficult to find the one you want.
(2012-12-16, 09:50 PM)Beardy Wrote: [ -> ]
(2012-12-16, 09:42 PM)dalawh Wrote: [ -> ]I just meant in general and was using that as an example. Any specific file you maybe referring to?

Template variables are usually defined right before a template is loaded in, they're not defined in one specific place. In terms of plugins, they're usually defined inside a hooked function and made global, so the template that is loaded after the function runs is able to access those variables.

A tip to finding out what data certain template variables hold is to use a text editor that can search across multiple files (Notepad++ is fairly useful, though I prefer Netbeans' search) and search the mybb files for '$templates->get("___")', replacing the underlines with the template you're viewing, and then browse up a few lines until you find the variable you're looking for. Or just search for the name of the variable, though in certain cases this may bring up quite a few results (possibly in the same file) and it may be difficult to find the one you want.

Any idea why I can't access a variable in certain files? I tried using a variable in member_profile_referrals and it doesn't work, but it works fine in member_profile.
(2012-12-17, 05:18 AM)dalawh Wrote: [ -> ]Any idea why I can't access a variable in certain [templates]? I tried using a variable in member_profile_referrals and it doesn't work, but it works fine in member_profile.

It's possible the variable was set after 'member_profile_referrals' was loaded. Template variables only have access to variables that are explicitly defined before the template is loaded, this is because the template is loaded and processed through PHP and then the processed output is stored into a variable, meaning any variables that are defined after it are inaccessible because the template is simply pre-processed text at this point.

A little side-note that might clear things up, the reason the template variables are wrapped in curly brackets is because PHP will process any variable inside a double-quoted string (the curly brackets are optional, but are usually added for clarity):

$phrase = "Hello world";

$sentence = "The phrase is '{$phrase}'.";

$sentence would then be "The phrase is 'Hello world'."
Templates are loaded in the same way $sentence is defined in the above code, except they're stored into variables like {$reputation} and {$referrals} which are then accessed through the main template (in your case, 'member_profile').



Forgive me if I'm explaining the obvious or sidetracking here, but I'm finding it hard to pinpoint your exact question.

Are you trying to solve a specific problem or just trying to gain general knowledge? I might be able to help you better if it's the former.