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

Why Twig filters and not functions? #5

Closed
mbontemps opened this issue Sep 3, 2011 · 6 comments
Closed

Why Twig filters and not functions? #5

mbontemps opened this issue Sep 3, 2011 · 6 comments
Labels

Comments

@mbontemps
Copy link
Member

@stof, could you elaborate a bit on why you have chosen to replace a function by a filter, ie:

{% knp_menu_render('main' } %}

has become:

{{ 'main'|knp_menu_render }}

In terms of logic, it is not intuitive to me…

@stof
Copy link
Collaborator

stof commented Sep 3, 2011

It has never been a tag. It was a function: {{ knp_menu(menu) }} in the previous version.
And a filter is more semantic than a function for this as it transform the input into another value (this is also the reason why the date filter is a filter in Twig, not a function)

@benjamindulau
Copy link

I agree with @mbontemps, it's not intuitive.

I'm not sure about the semantic thing. A filter transforms or adapts a value that already has a "meaning" (a date for instance).
Here, 'main' is used just to find something, it's not a value intended for display.

It has its place as a function argument => "Go find my menu named 'main' and render it".

@stof
Copy link
Collaborator

stof commented Sep 5, 2011

the filter accept 2 things: the menu object, or the name for the menu in the provider.

@benjamindulau
Copy link

Still, IMO perhaps both filter and method should be proposed. The filter transforms a menu object, and the method takes a menu name.

@weaverryan
Copy link
Contributor

I don't think I like having both a filter and a function (which behave differently), but I think that @benjamindulau is perfectly logical: filtering the menu object makes sense, but filter a string into a full menu just doesn't feel right.

Also, I think a function is more consistent with how the Symfony form framework works, and it's also consistent with how you render a menu in PHP (e.g. you pass the menu into a renderer).

So, +1 for making it a function again - I just think it's a little more understandable.

@stof stof closed this as completed in 132db72 Sep 8, 2011
@weaverryan
Copy link
Contributor

Thanks @stof!

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

4 participants