-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved template variable handling #20
Conversation
PHP magic methods can be used to imitate getting/setting of public variables on objects. This gets rid of the ugly $internal property. - Allows $template->internal = 'foo' - Better code clarity
Also, unless I'm missing something, this should make #9 trivial. extract($this->variables, EXTR_REFS);
// render template
foreach (array_keys($this->variables) as $key) unset($key); The unset bit is probably not even necessary. |
At first glance this looks good. Unfortunately it doesn't help with issue #9—the challenge there isn't extracting the variable available before you render, but rather those created while rendering. Nonetheless, this looks like an improvement. I'm going to have a closer look, and unless I find any issues I'll pull it in. Thanks for your interest and help on this project! |
You mean in terms of |
Exactly, and those variables created while using sections. |
Improved template variable handling
I don't know why this didn't cross my mind until now, but because the include is being called inside a class method, the protected variables are still available as |
Haha, yeah, I was going to say that earlier, but you actually led me to removing the need for |
PHP magic methods can be used to imitate getting/setting of public variables on objects. This gets rid of the ugly $internal property, which means
$template->internal
is no longer a reserved variable name, and the Template code is a lot clearer.