Include php files in templates
This short tutorial explains how to include php files in phpBB templates.
To include php files use usual php include(), include_once(), require() or require_once() function. Path to included file must be relative to phpBB root directory, not to tpl file. Use variable $phpbb_root_path to make sure path is always relative to phpBB root directory.
Example:
To include php files use usual php include(), include_once(), require() or require_once() function. Path to included file must be relative to phpBB root directory, not to tpl file. Use variable $phpbb_root_path to make sure path is always relative to phpBB root directory.
Example:
Code:
- include($phpbb_root_path ‘includes/my_file.php’);
 - include(‘myfile.php’);Â
Also note that template is included inside a funciton, so if you are using variables inside your php file and you have some functions that use those variables using “global” directive, you must declate those variables as “global” too. Example of valid included php code:
Code:
- // declare variable as global so it could be accessed from change_var()
 - global $myvar;
 - function change_var()
 - {
 -  // declare variable as global to access previously declared variable $myvar
 -  global $myvar;
 -  $myvar = 1;
 - }Â
Share this tutorial
Â