Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Trying to exclude certain types of nodes from the authcache by creating a custom ruleset. Problem is, I'm playing "guess and try" to see what global variables (get/post/request/session/etc) are available through that code. Any hints?
Comments
Comment #1
Jonah Ellison CreditAttribution: Jonah Ellison commentedThe PHP code is evaluated within the drupal_eval function. It adds the global variables $theme_path, $theme_info, $conf. You can also add global $user; and so on to access more global variables, and you can also call Drupal functions. It's pretty much like any other part of Drupal that allows PHP code.
Comment #2
wrightnow CreditAttribution: wrightnow commentedJonah, excellent response - I'm fairly new to Drupal and finding a coherent documentation source is a challenge.
Since you definitely have far more experience with the AuthCache ruleset system than I, do you have a suggestion for how to exclude certain CCK types (nodes) from caching? Or, alternatively, specify distinct CCK types to include in the cache? The default variables ($conf, $GLOBALS,$user) don't seem to point to the current node...
Comment #3
Jonah Ellison CreditAttribution: Jonah Ellison commentedSure, here is an example:
Comment #4
wrightnow CreditAttribution: wrightnow commentedThought I'd post the solution I came up with. For our site, 99% of our nodes are of a single CCK type, so we only need/want to cache those (The rest are dynamic). My solution was to add the following to our page.tpl.php rather than find a solution through the rulesets.
I'm very open to comments...
Comment #5
Jonah Ellison CreditAttribution: Jonah Ellison commentedYep, that can work as well, jww2nc.
There are many ways to do things in Drupal, though I would following certain standards. One is limiting code logic in template files in order to leave them as clean as possible for theming. I usually try to add theme logic to template.php. For example, you can use a preprocess function, like function YOURTHEME_preprocess_node(&$variables) { } to set $is_page_authcache to false (YOURTHEME_preprocess_page() can work as well, since $variables['node'] contains the node object).
Comment #6
wrightnow CreditAttribution: wrightnow commentedExcellent! I'm very familiar with the preprocess hooks.
Jonah, you've been very helpful - I very much appreciate the amazingly prompt responses. I'm going to close this issue since you've answered all my questions - hopefully thats the right procedure on Drupal boards...