I'm writing an application that will be managed by my team, it uses Mustache.php as template engine.
I have a PHP file that makes an array of variables and functions that is passed to the Mustache parser to populate the template.
I even provide a system to override partials of my template to edit the aspect of the application for specific users.
Now I'd like to add a way to allow my team to add custom variables to the array passed to Mustache.php without have to hack the core of my application.
I thought about a little function that checks if a .php file with the name of the user exists and if so, include it after I've generated the array and before I pass it to mustache.
It should looks like:
contents.php:
// my queries
$variables = Array(1,2,3,bla,foo,bar);
if (file_exists($_SERVER['BASE_DIR'] . '/customcontents/'. $username . '.php')) {
include($_SERVER['BASE_DIR'] . '/customcontents/'. $username . '.php');
}
// Call mustache and pass $variables to it
<username>.php:
// custom queries
$variables = array_merge($variables, $customvariables)
I'm not sure if this can be a nice solution or if you guys have some better idea.