2010-01-14 86 views
0

(注:我最初发布这个在drupal.org记住的是,我从来没有在那里的响应之前那么,遗憾的交叉发布)预处理功能

你好,有什么办法(内置或其他)为特定的cck节点类型添加预处理功能?我期待在我的cck节点类型中对字段进行一些预处理。目前,我可以使用theme_preprocess_node,然后在$ node-> type上进行切换,或者对某个特定字段名称使用主题化函数(并且仍然会执行切换以确保当前字段的使用情况在我正在查看的节点类型内对于)。我的建议是有这样的功能...

theme_preprocess_mynodetype(&$vars) { 
    // Now I can preprocess a field without testing whether the field is within the target content type 
} 

...但我想不通,如果我可以建议预处理功能,以同样的方式我可以建议模板文件

谢谢! Rob

回答

1

我认为你在寻找this post。没有神奇的每个节点预处理,只有每个主题/模板引擎,但是您可以访问$ vars参数中的节点类型,因此您可以在那里打开它。

希望有帮助!

+0

嘿感谢,我看到了一个但此功能使用节点预处理器有开关,这点我是试图避免(有点)来停止预处理器从成长到庞大。 我想我可以用一个实际调用theme_preprocessor_cat(),theme_preprocessor_dog()等的开关来使用theme_preprocessor_node。但是,也许没有自动方式或无法建议预处理函数(tpl文件的建议方式)? – rob5408 2010-01-14 19:13:06

+0

将此标记标记为已接受,因为我一直在寻找“没有任何神奇的每节点预处理”,但Nikit的回答给出了解决方法。 – rob5408 2011-02-07 15:21:51

3

看到这个函数在CCK的content.module:

 

/** 
* 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']; 
... 
 
+0

感谢您的关注。在这个函数中,CCK实际上建立了tpl文件的建议,但不是预处理函数(从我可以告诉的内容),但它导致我通过content.module挖掘更多。将发布我发现的内容。 – rob5408 2010-01-15 10:12:51