例如:node里面有一个field_image的字段,读取他的默认显示样式:
方法1:
1 2 3 | $node = node_load( $nid ); $content = node_view( $node , 'full' ); $row [ 'image' ] = drupal_render( $content [ 'field_image' ]); |
方法2:
1 2 3 | $node = node_load($nid); $content = field_view_field( 'node' , $node, 'field_image' ); $row[ 'image' ] = render($content); |
如果你想应用后台内容类型的设置显示格式,就需要改写代码:
1 2 3 4 5 6 7 | $node = node_load($nid); // Must load field content for entity before using field_view_value() $fields = field_get_items( 'node' , $node, 'field_image' ); // $index corresponds to the value you want to render. First value = 0. $index = 0 ; $content = field_view_value( 'node' , $node, 'field_image' , $fields[$index]); $row[ 'image' ] = render($content); |
如果想自定义样式,可以
1 2 3 | $display = array( 'type' => 'my_formatter' ); $content = field_view_field( 'node' , $node, 'field_image' , $display); $row[ 'image' ] = render($content)' |