1

We include an external script from a vendor and the URL doesn't end in .js. It returns JavaScript that creates a widget in place. I was able to fake it out by adding a '&js=.js' parameter but it still rendered with the other scripts.

Is there an option for {% js %} to render in place? A {% js at right-here %}?

3
  • 1
    I may be missing something here, but you probably just want to use the <script> tag?
    – dmatthams
    Dec 3, 2020 at 9:07
  • I may be too. That's the only thing I've got working so far, but I'm not sure if there's a standard way to do it.
    – ponies
    Dec 3, 2020 at 19:12
  • The {% js %} tag can only inject javascript at the end or beginning of the page so it's fine to use the <script> tag if you need something in place.
    – dmatthams
    Dec 4, 2020 at 9:33

1 Answer 1

1

In your template you can use the <script src=""> tag as it's a combination of the html and twig. So it will load your external javascript files.

Also you can use the inline javascript or javascript file using this tag {% js %} like below.

{# Use for JS file #}
{% js "/assets/js/script.js" %}

{# Use as a JS code block #}
{% js %}

console.log("hello World");    

{% endjs %}
1
  • Inside a {% js %} block, could you pull in an external script and run it?
    – ponies
    Dec 24, 2020 at 0:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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