2014-08-21, 11:09 PM
Right now you can't deny the current method of rendering templates is... ugly. And way too easy to mess up.
What if there were a cleaner, easier to use way?
Adding such a function would help clean things up and make script-breaking typos more difficult. Here's mine:
The hard part would be updating the entire codebase to use this function...
Edit: Actually it might make more sense to add it to the Templates class, a la this:
Unfortunately due to the way the whole thing works it still has to be wrapped in the eval() rather than moving it in to the function, but it's a good step in the right direction.
eval("\$addevent = \"".$templates->get("calendar_addevent")."\";");
What if there were a cleaner, easier to use way?
eval(render_template('addevent', "calendar_addevent"));
Adding such a function would help clean things up and make script-breaking typos more difficult. Here's mine:
function render_template($var, $temp, $append = false)
{
global $templates;
return '$' . $var . ($append? ' .= "' : ' = "') . $templates->get($temp) . '";';
}
The hard part would be updating the entire codebase to use this function...
Edit: Actually it might make more sense to add it to the Templates class, a la this:
eval($templates->render($template, $variable, $append));
Unfortunately due to the way the whole thing works it still has to be wrapped in the eval() rather than moving it in to the function, but it's a good step in the right direction.