0

I'm trying to display a div container after each field item with the name additional_content of my page content type. Right now im trying to preprocess my field but i can't go down to the real field item i want to proprocess...

Is it better to override the template? And how would that work? i have a field called additional_content integrated into my page content type. After this has been printed i want to add a div container to each of this items.

Any help with that?

  • So you want to wrap entire field content with <div> and </div>? – user11153 Mar 29 '13 at 18:21
  • @user11153 no i just want to append a <div></div> Thanks for asking – Jurudocs Mar 29 '13 at 18:23
1

Copy modules/field/theme/field.tpl.php file into sites/all/themes/YOUR_THEME/templates

Rename it to field--additional_content--YOURCONTENTTYPENAME.tpl.php
(or only field--additional_content.tpl.php if you want to change its template for all content types)

Edit its template like this:

<div class="<?php print $classes; ?>"<?php print $attributes; ?>>
  <?php if (!$label_hidden): ?>
    <div class="field-label"<?php print $title_attributes; ?>><?php print $label ?>:&nbsp;</div>
  <?php endif; ?>
  <div class="field-items"<?php print $content_attributes; ?>>
    <?php foreach ($items as $delta => $item): ?>
      <div class="field-item <?php print $delta % 2 ? 'odd' : 'even'; ?>"<?php print $item_attributes[$delta]; ?>><?php print render($item); ?></div>
      <div class="your-additional-div"></div>
    <?php endforeach; ?>
  </div>
</div>
| improve this answer | |
  • you are right...its just that simple...i tried that but always foot to add the tpl. grrr – Jurudocs Mar 29 '13 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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