I wouldn't want to make the same mistake as in Symfony 1 and introduce implicit things again.
On 8 Jul., 00:14, Lukas Kahwe Smith <[email protected]> wrote: > Hi, > > Right now when rendering and passing in a scalar/object variable or a single > list, it is necessary to wrap things into an array to give twig a variable > name: > > $this->templating->render($template, array('article' => $article)); > $this->templating->render($template, array('article_list' => $articles)); > > imho it would be nicer if one could just write: > > $this->templating->render($template, $article); > $this->templating->render($template, $articles); > > In order to be able to do this twig could simply always define an implicit > variable, f.e. "params", that points to all the parameters passed, whatever > they were. > Now obviously for a numerically indexed list this would not work as we cannot > define variables with numbers as names. However the solution is to simply not > define any variables in that case aside from the "params". > > $article = new Article(); > $this->templating->render($template, $article); > > would allow for > {{ params.title }} > > array(new Article(), new Article()); > $this->templating->render($template, $articles); > > would allow for > {{ params[0].title }} > > array('foo' => new Article(), 'bar' => new Article()); > $this->templating->render($template, $articles); > > would allow for > {{ params[0].title }} > {{ foo.title }} > {{ bar.title }} > > This would essentially be fully BC, except that this new variable would be > defined, but which if passed as a key would likely be overwritten. > > $this->templating->render($template, array('params' => 'foo')); > > would result in outputting 'foo' > > {{ params }} > > So in practice the only BC break would be > > $this->templating->render($template, array('bar' => 'foo')); > > {% if params is defined %} > > Also note that the name "params" is just a proposal. Maybe it should rather > be "twig.params" and "$php_params", which would further reduce the chances of > a BC break. > > regards, > Lukas Kahwe Smith > [email protected] -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups "symfony developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/symfony-devs?hl=en
