I have client site with a few different books in it. There are also some basic pages and other nodes that are not within the books. When you are in the first book the sidebar is blue, when you are in the second book the sidebar is green and the the third has an orange sidebar. This is controlled by a class that is applied to the body from a field in the book module.

Currently, when you access a global page (meaning a page or view outside a book) the sidebar color is a default color. But the client wants these global pages' sidebar color to stay the same as the last viewed book and not switch to a different color until a new book is viewed.

I am not even sure how to begin to go about doing this and am looking for ideas.


  • It's pretty simple. You use jQuery with jquery.cookie to grab the class/id that controls the color and create a cookie that stores the value. I assume the book pages must all have an unique div ID to them, that non book page do not have. So on page load you check if that ID is there or not. If it's there, which means ur on a book page, you store the class/id that controls the color in a cookie. If it's not there, it means that it's not a book page and you inject the class/id of the cookie value.
    – No Sssweat
    Commented Sep 7, 2016 at 23:18

1 Answer 1


Thanks to No Sssweat's comment my solution for this was to use Jquery to look for the body class that controls the sidebar color then use jQuery.cookie (already packaged in Drupal just need to make sure it loads on every page) to set a cookie with that value. Then if a page visited that doesn't have the body class that indicates it was a book and therefore also doesn't have the color class then I had jQuery .addClass to add the cookie value to the body element.

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.