PHPBB : Add new variables to template code

Let us talk about scripts, HTML, Perl, PHP, apache, etc.
Post Reply
User avatar
Stevyn
SysOp
Posts:1745
Joined:Mon Nov 09, 2009 10:03 am
Location:Japan
Contact:
PHPBB : Add new variables to template code

Post by Stevyn » Thu Apr 08, 2021 8:17 am

Add new variables to template code

/includes/functions.php

Find somewhere around line 4415:

Code: Select all

// The following assigns all _common_ variables that may be used at any point in a template.
example, make "user rank" as a template variable:

Code: Select all

	$$userRank  = "";
	$sql="SELECT * FROM " . phpbb_users . " WHERE user_id = {$user->data['user_id']}";
        $result = $db->sql_query($sql);
       $row = $db->sql_fetchrow($result);
      $userRank = $row['user_rank'];
add it in:

Code: Select all

	// The following assigns all _common_ variables that may be used at any point in a template.
	$template->assign_vars(array(
		'USER_RANK'		=> $userRank,
		'SITENAME'						=> $config['sitename'],
		'SITE_DESCRIPTION'				=> $config['site_desc'],
		'PAGE_TITLE'					=> $page_title,
		'SCRIPT_NAME'					=> str_replace('.' . $phpEx, '', $user->page['page_name']),
		'LAST_VISIT_DATE'				=> sprintf($user->lang['YOU_LAST_VISIT'], $s_last_visit),
		'LAST_VISIT_YOU'				=> $s_last_visit,
		'CURRENT_TIME'					=> sprintf($user->lang['CURRENT_TIME'], $user->format_date(time(), false, true)),
		'TOTAL_USERS_ONLINE'			=> $l_online_users,
		'LOGGED_IN_USER_LIST'			=> $online_userlist,
		'RECORD_USERS'					=> $l_online_record,
...
also check out

https://wiki.phpbb.com/Queries_in_phpBB3
Contact me directly: Ironfeatherbooks (@) gmail.com

Image

User avatar
Stevyn
SysOp
Posts:1745
Joined:Mon Nov 09, 2009 10:03 am
Location:Japan
Contact:

Re: PHPBB : Add new variables to template code

Post by Stevyn » Wed Jun 22, 2022 7:19 pm

https://area51.phpbb.com/docs/dev/3.3.x ... lates.html

UPDATE; much nicer system for newer phpbb

Assign a single variable:

Code: Select all

$template->assign_var('FOO', $foo);
Assigning multiple variables:

Code: Select all

$template->assign_vars([
    'FOO' => $foo,
    'BAR' => $bar,
    'BAZ' => $baz
]);
Contact me directly: Ironfeatherbooks (@) gmail.com

Image

Post Reply