I have a text field attached to my node. The user can add an unlimited number of values.

I want to out put all the values as a HTML list in my node.tpl.php file.

Contemplate module suggests to use the following code to out put the field:

<?php print $node->field_body_list['und'][0]['safe_value'];?>

This, however, has two problems: 1) It only outputs the first value of the field. 2) It uses UND, which is apparently bad.

I have tried using theme developer, but it doesn't produce any code that I can use in my node.tpl.php file.

Any help would be greatly appreciated it.

1 Answer 1


It's easiest to stay out of node.tpl.php for this one and instead use a field specific template file.

You'll need two copies of /modules/field/theme/field.tpl.php in your theme folder. The first is an exact duplicate with no changes and the same filename. The second you should rename to field--field-body-list.tpl.php. Consult Drupal 7 Template Suggestions if that filename doesn't work for you.

In field--field-body-list.tpl.php I would change the div with class="field-items" to <ul> and the div with class="field-item" to <li>.


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.