All I'm trying to do is display a CCK field on custom--node.tpl.php but it seems everything has changed in D7 and there are no documentation on this.
我要做的就是在custom - node.tpl.php上顯示一個CCK字段,但似乎D7中的所有內容都已更改,並且沒有相關文檔。
In Drupal 6 I did it like so:
在Drupal 6中,我這樣做了:
<?php print $node->field_myfield[0]['view'] ?>
In Drupa 7 I did it like so:
在Drupa 7中,我這樣做了:
The problem is that this field is html formatted and I really don't want that. How can I print/echo/display a CCK field on custom--node.tpl.php with my own formatting provided by my own CSS or template file?
問題是這個字段是html格式化的,我真的不希望這樣。如何使用我自己的CSS或模板文件提供的格式在custom-node.tpl.php上打印/回顯/顯示CCK字段?
2 个解决方案
#1
0
If you don't want to actually render the content, you should be able to access the raw value of the field like this, depending on the type of field:
如果您不想實際呈現內容,則應該能夠像這樣訪問字段的原始值,具體取決於字段的類型:
<?php print $node->field_myfield[$node->language][0]['value']; ?>
#2
0
Get the formatted value of a cck field in Drupal 7:
在Drupal 7中獲取cck字段的格式化值:
$node = node_load($nid);
echo field_view_value('node', $node, 'field_YOUR_FIELD', node->field_YOUR_FIELD['und'][0]);
?>