Register Global(s) [Variables?]

Get help with installation and running phpBB 3.0.x here. Please do not post bug reports, feature requests, or MOD-related questions here.
Scam Warning
Forum rules
END OF SUPPORT: 1 January 2017 (announcement)
Locked
User avatar
Kestral
Registered User
Posts: 18
Joined: Sun Jan 18, 2009 12:31 am

Register Global(s) [Variables?]

Post by Kestral » Mon Jan 19, 2009 10:59 pm

I want to know how I can add something like {SITE_IMG_LOGO} or {U_INDEX} to use.

I know I'm being vary vague so I'll elaborate:

I want to register new globals for use. For example, I define {row_tue} as 4, I want to use {row_tue} in JavaScript to define a variable.

Or something along with the lines of that.

I'm also wondering if I can use pre-existing globals in custom BBcodes.

Mr. Bond
Registered User
Posts: 54
Joined: Mon Feb 04, 2008 1:11 pm

Re: Register Global(s) [Variables?]

Post by Mr. Bond » Mon Jan 19, 2009 11:24 pm

Template variables is what they are called. ;)

If you want to add them you use $template->assign_vars() or $template->assign_var()

Code: Select all

$template->assign_vars(array(
    'MY_VAR'      => 'This is a template variable',
    'YOUR_VAR'    => 'Another template variable',
)); 
Or if you want to be able to use the variable anywhere in your template it needs to go in the page_header() function in /includes/functions.php

Open: /includes/functions.php

Find:

Code: Select all

    // The following assigns all _common_ variables that may be used at any point in a template.
    $template->assign_vars(array( 
And after that you can add your template variable(s):

Code: Select all

'VAR'                => 'Variable :)', 
I'm also wondering if I can use pre-existing globals in custom BBcodes.
To my knowledge, that is not possible.

User avatar
Kestral
Registered User
Posts: 18
Joined: Sun Jan 18, 2009 12:31 am

Re: Register Global(s) [Variables?]

Post by Kestral » Mon Jan 19, 2009 11:27 pm

So I can use them in instances such as this:

Code: Select all

<script type="text/javascript">
var {VAR}={VARVALUE};
</script>
Edit: I know that the syntax would be correct if you use the {VAR} from the above post.

Locked

Return to “[3.0.x] Support Forum”