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
}

...但我不知道是否可以像建议模板文件一样建议预处理功能

谢谢!抢

4

2 回答 2

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'];
...

于 2010-01-15T01:10:28.773 回答
1

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

希望有帮助!

于 2010-01-14T19:03:57.717 回答