In this paper, we describe the method of using JS variable in twig. Share to everyone for your reference, as follows:
Look at a piece of code first
The address of this AJAX request is not properly accessible.
In this code, JQuery ("#my_input"). Val () values are assigned to value, and then you want to introduce the value variable into the URL address in Ajax.
At this point you will find that the value of the address you are visiting is not introduced, but is treated as a string.
That is, the value of JS can not be directly quoted in the Twig.
The reason is that twig parses a PHP variable, and value is a JS variable, so twig is considered a string by default.
So we need to replace, we'll use replace.
The code below, you can compare with the above code itself:
Permanent address of this article: http://blog.it985.com/7020.html
This article is from IT985 blog, please indicate the source and corresponding link when reproduced.
More about PHP template related content readers can view the site topics: "PHP Template Technology Summary", "Smarty Template Primer Basic Tutorial", "CodeIgniter Introductory Tutorial" and "thinkphp Introductory tutorial"
I hope this article is helpful to you in PHP programming.