Here is a div that I append in AJAX with a script (at the bottom of the TWIG file) : If I then click on the freshly appended button, it returns an error because the ID “vote.id” is still 0 until I reload the page and the ID gets found… Is there a way to trigger the for loop without
Tag: twig
How can I use javascript code in an external file with twig elements?
I have a lot of javascript code one my twig template home.html.twig, for example: Because the source code of my main page is now full of javascript I try to move it into an external file, to have a more clean appearance: But it does not work because I have so much twig variables, and they are not recognized anymore.
Pass javascript variable to twig
I just want to pass a javascript variable to a twig path. Now i’m using this, but it doesn’t work. Answer Note You should really look at the FOSJsRoutingBundle.
how to keep double quotes in twig?
I have a json array that I pass to the twig template, but the double quotes in the array have been causing trouble, my json array is like this: in twig template, I print it out like this: I expect it to be attrs: [“a”, “b”], however, what gets output is attrs: ["a", "b"], I tried attrs: {{ arr|e(‘js’) }},
Pushing an array in js doesn’t look to work properly
I have this array from my controller which is passed to my twig where I execute the below code to parse it into a js array: The problem is that $flight.length returns 4 instead of 2, the ReturnFlightSegmentDetails is considered like an object instead to be an attribute for a flight. Answer You need to build the “flight” object differently;