Skip to content
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

Extract variables #17

Closed
lekoala opened this issue Jun 11, 2014 · 2 comments
Closed

Extract variables #17

lekoala opened this issue Jun 11, 2014 · 2 comments
Labels

Comments

@lekoala
Copy link

lekoala commented Jun 11, 2014

Hello,

Is there a reason why the variables are not extracted to be available in the template without using $this ?
I find it more convenient to use than var ?>

I believe it would require just this line before each include
extract(get_object_vars($this));

@reinink
Copy link
Contributor

reinink commented Jun 11, 2014

Thanks for your interest in Plates! This is not an uncommon question, and while it seems simple enough at first, much of the power of Plates comes from that fact that templates are objects. Yes, the manually assigned variables could be extracted in this way before rendering, however any variables that are created during the rendering process (ie. via inheritance, nesting and extensions) will not be in the local scope and must be accessed using the $this pseudo-variable. Because of this, it only makes sense to maintain a consistent approach to variable accessing.

I personally spent a bunch of time trying to find a smart way of removing the $this pseudo-variable from Plates—see issue #9 for more details (in particular the section on "Consistency with variable access"). When using compiled languages (like Twig) you have the freedom to change the syntax however you'd like. When using native PHP templates, you're working within the constraints of the language, and some things (like $this) are unavoidable.

@reinink
Copy link
Contributor

reinink commented Jun 30, 2014

Actually rethinking how this could be possible. See #21. Feedback appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants