On 08.07.2011, at 09:18, Lukas Kahwe Smith wrote:

> On 08.07.2011, at 08:12, Lukas Kahwe Smith <[email protected]> wrote:
> 
>> On 08.07.2011, at 07:59, Fabien Potencier 
>> <[email protected]> wrote:
>> 
>>> On 7/8/11 12:14 AM, Lukas Kahwe Smith 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);
>>> 
>>> You can do:
>>> 
>>> $this->templating->render($template, compact($article));
>>> $this->templating->render($template, compact($articles));
>>> 
>>> or even:
>>> 
>>> $this->templating->render($template, compact($article, $articles));
>> 
>> compact() is nice when you have multiple parameters, but not really if you 
>> have just one. 
>> 
>> i guess i didnt mention how i came to this proposal. the issue is that in 
>> FOSRestBundle if i set parameters which can either used for html or json/xml 
>> output it sucks to be forced to wrap everything in an array just to make the 
>> template engine happy. 
>> 
>> my suggestion would solve the issue. but it would imho also be more elegant 
>> and efficient for the non FOSRestBundle case, which os why i suggested it 
>> out of this context. 
> 
> i should note that unless core is changed i will just add code to the 
> restbundle htmlencoder to check if the parameters are either a non array or a 
> numerically indexed array and i that case wrap the parameters in an array 
> with the key "params". 


i have solved the issue inside the FOSRestBundle HtmlEncoder:
https://github.com/FriendsOfSymfony/FOSRestBundle/commit/ef5bda6a68ad2e93af581e4016886e50df29ca73

This allows code like the following:
https://github.com/liip/LiipHelloBundle/commit/fadd6b32d2e756d0829e621733a3639909190b44

As you can see the "numerically ordered array" detection is a very simplistic 
in order to not add too much overhead.

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

Reply via email to