variable jquery inside twig template

前端 未结 2 705
被撕碎了的回忆
被撕碎了的回忆 2021-01-06 00:04

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:



        
2条回答
  •  长发绾君心
    2021-01-06 00:42

    The problem is that Twig is launched before than JavaScript and the variable "id_emergencia" is not recognized by Twig. You could do a trick. You can put a string, as a parameter and then, in the JavaScript code, you replace the string with the value of your variable. In this way, you will always have the correct url before your AJAX petition is launched.

    You could do something like this:

    
    

提交回复
热议问题