1

Is there any way to add javascript in craft

1

You can use {% js %} Twig tag. It is essential to using JS in Twig. It takes JS code passed to it and appends it at end of the template, right before ending body tag. Multiple js tags can be used - content from each of them will be concated with the rest. You don't need to wrap code passed to {% js %} into <script> tags - js will do that for you.

{% js %} 
    console.log('Hello World');
    /* you can add your js code here */
{% endjs %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.