Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
14
rated 0 times [  20] [ 6]  / answers: 1 / hits: 46115  / 10 Years ago, tue, december 9, 2014, 12:00:00

Is there some way to pass variables from twig to javascript file that lay in public/js directory of bundle. Or do I need to assign my variables in template and then include my script file where vars will be used?


More From » php

 Answers
184

Assign the variable in the template and pick it up with javascript...



<script>
var foo = '{{ foo }}';
alert(foo);
</script>

[#68539] Friday, December 5, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
clarkulisesa

Total Points: 422
Total Questions: 93
Total Answers: 112

Location: Austria
Member since Thu, Jan 7, 2021
3 Years ago
clarkulisesa questions
Mon, Feb 24, 20, 00:00, 4 Years ago
Mon, Aug 12, 19, 00:00, 5 Years ago
;