2010-01-14 110 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