(Note: I originally posted this on drupal.org before remembering that I never get a response over there. So, sorry for the cross-posting)
Hello, is there a way (built-in or otherwise) to add preprocessing functions for particular cck node types? I am looking to do some preprocessing of a field within my cck node type. Currently I can either use theme_preprocess_node and then do a switch on the $node->type or use a theming function for a particular field name (and still do a switch to make sure the current field usage is within the node type i'm looking for). What I am suggesting is to have a function like this...
theme_preprocess_mynodetype(&$vars) {
// Now I can preprocess a field without testing whether the field is within the target content type
}
...but I can't figure out if I can suggest preprocess functions the same way I can suggest template files
Thanks开发者_运维知识库! Rob
See this function in content.module of cck:
/**
* Theme preprocess function for field.tpl.php.
*
* The $variables array contains the following arguments:
* - $node
* - $field
* - $items
* - $teaser
* - $page
*
* @see field.tpl.php
*
* TODO : this should live in theme/theme.inc, but then the preprocessor
* doesn't get called when the theme overrides the template. Bug in theme layer ?
*/
function content_preprocess_content_field(&$variables) {
$element = $variables['element'];
...
I think that you're looking for this post. There's no magic per-node preprocess, only per theme/template engine, but you do have access to the node type in the $vars parameter so you can switch on it there.
Hope that helps!
精彩评论