Javascript-twig template rendering mechanism can I use jquery in twig?

Source: Internet
Author: User

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.onloadcan also be used.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.