MyBB Community Forums

Full Version: Custome $mybb var not working in template
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys i am loading a new set of vars into the $mybb array. I need to show some of the values that where added inside the forum tenplate systeme.

Inside the load_user() funtion in class_session.php i added the following code:

        if ($mybb->user['uid']){
            
            // User is connected lets attach his game account array
            function game_stuff($username){
                
                // Get account info
                $mysql_connect1 = @mysql_connect("***", "***", "***") or die(mysql_error());
                @mysql_select_db("***");
                
                $array[account] = mysql_fetch_array(mysql_query("SELECT * FROM account WHERE username=upper('$username')"));
                
                @mysql_select_db("***");
                
                $array[site] = mysql_fetch_array(mysql_query("SELECT * FROM account_data WHERE id='".$array[account][id]."'"));
                
                // Get chatacter data
                @mysql_select_db("***");
                $select = mysql_query("SELECT * FROM characters WHERE account='".$array[account][id]."'");
                while($char = mysql_fetch_array($select)){
                    $array[characters][]=$char;
                }
                
                return $array;
                
            }
            
            $mybb->game = game_stuff($mybb->user['username']);
                
        }

I dumped the array and i can see the new values added to $mybb->game

So what i am trying to du is add one of those values inside the header_welcomeblock_member template.

I added <span>{$mybb->game['site']['vp']}</span>

But the value is empty ... When i echo $mybb->game['site']['vp'] outside the template systeme i get the correct value...

What did i miss? Thx in advance!
Guess you need to do this in global.php before evaluating the desired welcomeblock template.
As effone hinted, you will need to hook into global_start in order to populate the variable before the template is evaluated. Also, I would use the built in DB_* classes via the $db global variable rather than using the mysql_* functions (which themselves are deprecated within PHP anyway).
I tried adding it in global.php right after the session is initiated and it did not work ... Where is the global start hook code?
^ global_start hook code is around line 101 in the global.php file
Also, always wrap non-numeric array indexes with quotes ($array['site']).