Community Documentation

Modifying your Drupal theme for Authcache

Last updated December 13, 2010. Created by Jonah Ellison on December 12, 2010.
Log in to edit this page.

The golden rule for Authcache is: the final cached page HTML must be the same for every user! For example, if you set up the "paid members" role to receive cached pages, then the final source HTML must be the same for each person for cached pages within this role.

The most common theme element for logged-in users is a username link (e.g. "Hello, [username]"). Authcache defines several new variables to use in your theme files (e.g., page.tpl.php):

  1. $user_name to display the logged-in user name
  2. $user_link to display the name linked to their profile (both work for cached and non-cached pages).

You'll need to modify your .tpl files to use these variables if you display a username or a link to a user's account page.

A global variable named $is_page_authcache is set to TRUE when a page is to be cached. This variable may change to FALSE during page generation, however, such as when a status message is displayed. You may also set it to FALSE to programmatically disable caching.

The authcache_preprocess() function defines these variables. For example, if a page is to be cached, then the output of $user_name will be <span class="authcache-user"></span>. The value will then be filled in automatically by Authcache JavaScript. The username and user id is retrieved from a cookie that is created when a user logs in.

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Programmers, Site administrators
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.