0

I need to add js file with jQuery syntax on a specific content type.

I tried on twig template but I get jQuery or $ not a function,

If I have js native syntax only, it is working great but not with jQuery syntax.

I think that this is not the right way to add a js depend jQuery file to a specific page.

I an wondering, What is the right way to do it?

Thanks a lot.

1 Answer 1

0

Checkout https://www.drupal.org/docs/8/creating-custom-modules/adding-stylesheets-css-and-javascript-js-to-a-drupal-8-module especially section Attaching a library in a twig template

See also lib/Drupal/Core/Render/theme.api.php where the library is like $build['#attached']['library'][] = 'core/jquery';

{{ attach_library('core/jquery') }}

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.