3

It seems with login user jQuery Cookie added and worked correctly but when I visit my website with not login user(anonymous) then I faced with TypeError: $.cookie is not a function. Why This happened and how can I attach jQuery cookie libraries for not logged in users by default?

Notes: My theme is based on Drupal Bootstrap theme

5
  • By default no libraries are attached, like in D7 so in your theme or module you have to define library that depends on jquery and/or the cookie library and attach it.
    – user21641
    Jul 13, 2016 at 12:53
  • in drupal 7 I got jquery.cookie.js file and put it in theme file and in theme.info add it. but it seems it exists here and it is not require I download and add it like drupal 7, is this right? tell me what is the solution for this ?
    – Yuseferi
    Jul 13, 2016 at 12:58
  • drupal.org/developing/api/8/assets
    – user21641
    Jul 13, 2016 at 13:22
  • @IvanJaros you mean I have to manually add it to my theme?
    – Yuseferi
    Jul 14, 2016 at 7:30
  • @IvanJaros can you provide some snippet as answer for this question?
    – Yuseferi
    Jul 20, 2016 at 6:23

1 Answer 1

9

For available Jquery and Jquery cookie for anonymous user, it should add it on theme libraries dependencies , as example if your theme name is themename on themename.libraries.yml add

in Drupal 8

  dependencies:
    - core/jquery.cookie

(Drupal 9 Deprecated core/jquery.cookie and will remove in D10.)

then in Drupal 9 and 10 use

  dependencies:
    - core/js-cookie

Thanks @Mr.Thi to mention this

1
  • Drupal 9 Deprecated core/jquery.cookie and will remove in D10. use core/js-cookie instead. drupal.org/node/3104677
    – mr.Thi
    Oct 4, 2021 at 11:50

Your Answer

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

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