I need to order my field in a node_preprocess to display it in a ul.

I have this field:
field_gallery[2 imgs with title..],
field_video [a link list.. rendered with videojs module],
field_video_desc [a text field..]

I need to render they in 2 lists:

function mytheme_preprocess_node(&$variables){

  $rendered_field = mytheme_field_HTML($variables);

  $element = array (
     $rendered_field['video'] );  

  $text = array (
     $rendered_field['video_desc'] ); 

  $variables['elements'] = theme_item_list(array('items' => $element, 'type' => 'ul'));
  $variables['texts'] = theme_item_list(array('items' => $text , 'type' => 'ul'));

but I need to write mytheme_field_HTML() function and I don't understand how, using Field API, I can retrive the HTML according the default field display used in the current node.

How can I achieve this?

1 Answer 1


What about leaving the rendering of fields by Drupal and putting your list directly in the template?

Depending the condition about your node rendering, can be based on 1 particular node, or by content type, ... you can use a separate tpl file. For example, if its for a content type gallery, you can create a node--gallery.tpl.php in the templates folder of your activated theme.

Inside the tpl, you can create an HTML structure like this:

<!-- content node part -->
<div class="content"<?php print $content_attributes; ?>>
        <li><?php print render($content['field_cover']); ?></li>
        <li><?php print render($content['field_gallery_0']); ?></li>
        <li><?php print render($content['field_gallery_1']); ?></li>
        <li><?php print render($content['video']); ?></li>
        <li><?php print render($content['body']); ?></li>
        <li><?php print render($content['field_gallery_0_title']); ?></li>
        <li><?php print render($content['field_gallery_1_title']); ?></li>
        <li><?php print render($content['video_desc']); ?></li>

    <!-- remaining unrendered fields -->
    <?php print render($content); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.