2010-09-28 56 views
2

我試圖在我的node.tpl.php文件中打印CCK字段 - 這樣的文件; print $node->field_name_here[0]['view']; 但是,當我導航到該頁面時,我看不到內容。 即使當我使用print_r($node);我看不到有關該變量的任何信息。 Drupal僅在node.tpl.php文件中呈現其他所有內容。無法在Drupal模板中打印CCK字段

但是...如果我通過把die();print_r() print $node->field_name_here[0]['view']; 的CCK後場的任何位置停止node.tpl.php的執行/可變渲染,因爲它應該。

這不是權限問題,因爲我允許所有用戶查看這些字段的內容。我甚至嘗試禁用和卸載CCK字段權限-module,但仍無法正確地在我的模板中打印CCK字段。

我在這裏錯過了什麼?

+1

您是否檢查過預期輸出的頁面源代碼? 'die();'語句通常對已經打印的東西沒有任何影響,所以我懷疑你的輸出是在頁面上,但是由於CSS/Markup在瀏覽器中不可見。 – 2010-09-29 06:10:03

回答

3
$node = (object) $node; 
$node = node_build_content($node, $teaser, $page); 
$content = drupal_render($node->content); 
// Allow modules to modify the fully-built node. 
node_invoke_nodeapi($node, 'alter', $teaser, $page); 
return $node;

上只是通過你的加載點與代碼。這上面的行會回報你的[視圖]的節點。

0

檢查內容類型顯示選項卡。 example.com/admin/content/node-type/{content-type}/display

很有可能您嘗試使用的字段的顯示設置爲「無」複選框「排除「被檢查。

0

不應該是以下幾點?

print $node->field_name_here[0]['value']; 

取而代之? (值,而不是視圖) - 在腳本中我存取權限他們這樣的,它也顯示該節點的devel的標籤