I\'m trying to use a jquery varaible inside a twig template to send by ajax, but I can\'t access to the jquery variable inside the twig:
My code is:
Of course it does not exist.
The value
variable is just plain text for Twig. Remember:
First the Twig parts are rendered, then it gets outputted to the browser, then the Browser renders the content and executes the Javascript.
The line {{ path('ParteAccidentes_ajax', {'emergencia': value}) }}
is executed way before value
is event parsed as javascript.
Also you're doing this in an event handler.
How should twig (since it's just a PHP library) change the path url on a executed javascript event?
Since you just want to update an URL based on symfony paths and a javascript variable, please have a look at this bundle: https://github.com/FriendsOfSymfony/FOSJsRoutingBundle
It provides the exact functionality you want.