1: Encounter a problem with twig
A template page is defined, and then the child page inherits it.
If you cannot write any code outside of the {percent percent} tag, you will get an error. As shown, a piece of code is written in the label, and the browser errors, such as:
My jquery was introduced in the template page. When I put this piece of code in the JS file and introduced it in the template page, there is no problem.
Here I would like to ask, what is the twig rendering mechanism? Why can't I use $ on this side?
Thank you
Just looked at it. The Sub-page is actually available after you join jquery directly in the sub-page. $ can be used.
If it is a reference to some of the public resources, in the template page will appear in this situation, how to ensure the common nature of these resources?
Reply content:
1: Encounter a problem with twig
A template page is defined, and then the child page inherits it.
If you cannot write any code outside of the {percent percent} tag, you will get an error. As shown, a piece of code is written in the label, and the browser errors, such as:
My jquery was introduced in the template page. When I put this piece of code in the JS file and introduced it in the template page, there is no problem.
Here I would like to ask, what is the twig rendering mechanism? Why can't I use $ on this side?
Thank you
Just looked at it. The Sub-page is actually available after you join jquery directly in the sub-page. $ can be used.
If it is a reference to some of the public resources, in the template page will appear in this situation, how to ensure the common nature of these resources?
When you execute JS on the page
JQ has not yet introduced
It doesn't matter with twig. But because your jquery is not loaded, the referenced $
code executes.
Try to put the code in
document.onload = function() { // 以下是你的代码}
Middle.
window.onload
can also be used.