PHP Variables in Templates
1. External Variables
Because template is included inside a function, all global variable must be declated with “global”. For example:
- echo $phpbb_root_path; // would show error – no such variable
Â
Â- global $phpbb_root_path;
 - echo $phpbb_root_path; // would echo phpBB variable $phpbb_root_pathÂ
Example for $_GET/$_POST/$_COOKIE variables when using old full length variables:
- if(isset($HTTP_GET_VARS[‘test’]))
 - {
 -  echo ‘test is set’;
 - }
 - else
 - {
 -  echo ‘test is not set’;
 - }Â
- global $HTTP_GET_VARS;
 - if(isset($HTTP_GET_VARS[‘test’]))
 - {
 -  echo ‘test is set’;
 - }
 - else
 - {
 -  echo ‘test is not set’;
 - }Â
2. Root Template Variables
There are three types of template variables in phpBB templates: root level variables like {U_LOGIN_LOGOUT}, {L_FAQ}, loop variables like {postrow.MESSAGE}, {catrow.forumrow.U_VIEWFORUM} and defined variables like {$VARNAME}
To access root level variables within php code in template files use $this->vars[‘VAR’]. For example, {U_LOGIN_LOGOUT} would be $this->vars[‘U_LOGIN_LOGOUT’];
To access defined variables within php code in template files use $this->_tpldata[‘DEFINE’][‘.’][‘VARNAME’]. For example, {$MYVAR} will be $this->_tpldata[‘DEFINE’][‘.’][‘MYVAR’];
3. Loop Template Variables
To access loop variable inside loop in php code in template use name of last loop, add “_item” to it. For example, {postrow.MESSAGE} would be $postrow_item[‘MESSAGE’];
For nested loops use only last loop item. For example. {catrow.forumrow.U_VIEWFORUM} would be the same as {forumrow.U_VIEWFORUM}: $forumrow_item[‘U_VIEWFORUM’];
Current loop iteration can be accessed as “_i”. For example, for “postrow” loop it would be $postrow_i
Number of loop iterations can be accessed as “_count”. For example, for “postrow” loop it would be $postrow_count