Twig variable in extern js file
问题 I want to external my js code but there is twig variable. What are your tricks ? team: {{ 'Select your team'|trans }} Thanks, 回答1: I just set my twig vars as globals before requiring any javascript files. <!DOCTYPE html> <html> <head> <title></title> </head> <body> <script> var my_twig_var = {% if twig_var is defined %}'{{ twig_var }}'{% else %}null{% endif %} </script> <script src="scripts/functions.js"></script> </body> </html> Another aproach I use is to forsee a javascript block in my