-
-
Notifications
You must be signed in to change notification settings - Fork 586
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
Adding context to twig extension #55
Conversation
I guess you pass the context to the template, or how do you create it? |
yea exactly, another way would be better i guess maybe an array option like {{ object|serializer('json', { 'groups' : ['foo', 'bar']}) }} |
That would be an option yeah, and should work well for the built-in things. Another idea, what do you think about something like:
|
I like it, its a bit long, but better than assign the context from the controller. |
Great, could you update your PR? |
*/ | ||
public function serialize($object, $type = 'json') | ||
public function serialize($object, $type = 'json', $context = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add a type hint to the parameter.
sure, i will do it tomorrow. |
{{ data|serialize('json', serialization_context().setGroups(['foo', 'bar'])) }} {{ data|serialize('json', serialization_context().setVersion('1.0')) }}
Ok updated my code. had to change groups to setGroups and possible version to setVersion. Sample {{ data|serialize('json', serialization_context().setGroups(['foo', 'bar'])) }}
{{ data|serialize('json', serialization_context().setVersion('1.0')) }} |
Adding context to twig extension
Thanks, merged! |
This pull requests addes the ability to set the context in twig.
i mainly need groups in the extension but only that would be bad for people which want to use versions aswell.
if this solution is accepted i could create a patch for serializerBundels Templating aswell.