Closed lekoala closed 10 years ago
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.
Actually rethinking how this could be possible. See #21. Feedback appreciated!
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 <?= $var ?> than <?= $this->var ?>
I believe it would require just this line before each include extract(get_object_vars($this));