Closed innocenzi closed 5 years ago
Hi
Can you fix the StyleCI issues? Also remove the typos here: https://github.com/rompetomp/inertia-bundle/pull/10/files#diff-40fe6fa51ee72630ed12a2bd2a76ade9R14
Is it possible to add tests for this feature?
Good looking out. Fixed those. I have added simple tests for the contexts, but I'm not sure how to test the serialization.
Thanks for the PR @hawezo
@rompetomp Any way to make a release someday? Thanks a lot 👍
Woops, sorry. Forgot about that. I'll do that right now ;-)
I think integrating the serializer component when it's available is a good idea.
I took inspiration from the
json()
method of Symfony'sControllerTrait
and put that in theTwig\InertiaExtension
class. I also added a third shared variable for giving context to the serialization.Basically, if the serialization component is not provided, the Twig extension still uses
json_encode
. But when it's available, it serializes the$page
with the given$context
.The context must be added as a parameter in the Twig template:
And you can either add shared context in an event listener like this:
Or add a specific context with the
render
method: