开发者

Display a CCK field (no formatting) in custom--node.tpl.php with Drupal 7

开发者 https://www.devze.com 2023-02-18 08:02 出处:网络
All I\'m trying to do is display a CCK field o开发者_StackOverflow中文版n custom--node.tpl.php but it seems everything has changed in D7 and there are no documentation on this.

All I'm trying to do is display a CCK field o开发者_StackOverflow中文版n custom--node.tpl.php but it seems everything has changed in D7 and there are no documentation on this.

In Drupal 6 I did it like so:

<?php print $node->field_myfield[0]['view'] ?>

In Drupa 7 I did it like so:

<?php print render($content['field_myfield']); ?>

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?


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


Get the formatted value of a cck field in Drupal 7:

<?php
$node = node_load($nid);
echo field_view_value('node', $node, 'field_YOUR_FIELD', node->field_YOUR_FIELD['und'][0]);
?>

Reference: http://plusfront.com/Drupal_6_Drupal_7_tip_Get_display_value_formatted_value_of_cck_fields

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号