Check your version

This video covers a topic in Drupal 7 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 7, but we consider it archived.

Alternate resources: 

Attachments and caching with the Render API

Video loading...

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:07
    Let's take a look at a couple of other things we can do
  • 0:09
    using renderable arrays.
  • 0:12
    One of the things that I'd like to do is make it so that our kitten image
  • 0:15
    has a red border around it on every page.
  • 0:18
    In order to do that, I can use CSS.
  • 0:20
    I can create a new .css file and have it loaded up on my module,
  • 0:24
    maybe inside of Drupal's hook_init,
  • 0:26
    I can load that CSS file and It would have some rules
  • 0:29
    that would put a red border around the image and that works.
  • 0:33
    But wouldn't it be nice if I could do it in a way

Attachments and Caching with the Render API


This chapter walks through how you can conditionally add either JavaScript or CSS to a content element as well as how to cache the content with Drupal's caching system. Additional notes: The cache will clear the first time cron.php is run AFTER whatever time you've specified as the cache expiration date in your code. Which you could easily calculate to be 30 seconds in the future and then store that timestamp in the database. However, you would also need to make sure that cron was running frequently enough to clear the cache every 30 seconds.

Log in or sign up to download companion files.
Additional resources: