代码之家  ›  专栏  ›  技术社区  ›  rob5408

CCK节点类型的预处理功能

  •  0
  • rob5408  · 技术社区  · 15 年前

    (注:我最初把这个贴在drupal.org上,然后才想起我从来没有在那里得到过回复。所以,很抱歉交叉发帖)

    您好,是否有一种方法(内置或其他)为特定的CCK节点类型添加预处理函数?我希望在CCK节点类型中对字段进行一些预处理。当前,我可以使用主题预处理节点,然后在$node->类型上进行切换,或者对特定字段名使用主题化函数(仍然可以进行切换,以确保当前字段的使用在我要查找的节点类型内)。我的建议是要有这样的功能…

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

    …但是我不知道是否可以像建议模板文件那样建议预处理函数

    谢谢!抢劫

    2 回复  |  直到 15 年前
        1
  •  1
  •   Chuck Vose    15 年前

    我想你在找 this post . 每个节点的预处理没有魔力,只有每个主题/模板引擎,但是您确实可以访问$vars参数中的节点类型,这样您就可以在那里打开它。

    希望有帮助!

        2
  •  3
  •   Nikit    15 年前

    请参见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'];
    ...
    
    
    推荐文章