开发者

Print fields in drupal

I'm trying to make Drupal print a list with two different fields in the same array. So first comes field A, then field B and it prints in this way until the whole array is printed.

The result I'm trying to get is something like

<tr>
  <td>Field_1[value1]</td>
  <td>Field_2[value1]</td>
</tr><tr>
  <td>Field_1[**value'n'**]</td>
  <td>Field_2[**value'n'**]</td>
</tr>

Until all values are printed.

EDIT. Figured out one way of achieving this directly in node--testnode.tpl.php.

<table>
<?php if ($content['field_test'][1]): ?>
        <tr><td><?php print render($content['field_test'][0])?></td><td><?php print render($content['field_test'][1])?></td></tr>
      <?php endif; ?>
<?php if ($content['field_test'][3]): ?>
        <tr><td><?php print render($content['field_test'][2])?></td><td><?php print render($content['field_test'][3])?></td></tr>
      <?php endif; ?>     
<?php if ($content['field_test'][5]): ?>
        <tr><td><?php print render($content['field_test'][4])?></td><td><?php print render($content['field_test'][5])?></td></tr>
      <?php endif; ?>   
</table>

Second fix, only manual work is to say how many repetitions you want.

<dl class="My Class">
        <?php
            $i = 0;
            $counter = 2 * render ($content['field_counter_slides'][0]) -1;
                while ($i <= $counter):
                    if ($content['field_test'][1]){
                        echo "<dt>";
                        print render ($content['field_test'][$i]);
                        $i++;
                        echo "</dt><dd>";
                        print render ($content['field_test'][$i]);
                        echo "</dd>";
                        $i++;
                    }
            开发者_JAVA百科    endwhile;
        ?>
    </dl>


It's quite hard to answer without knowing more but something like this would probably do it:

$header = array();
$rows = array();
foreach ($node->field_my_field[$langcode] as $key => $field_entry) {
  $rows[] = array(
    $field_entry['value'],
    $node->field_my_second_field[$langcode][$key]['value']
  );
}

$output = theme('table', array('header' => $header, 'rows' => $rows));

You'd have to make sure yourself that there are equal numbers of entries for each field so that there will always be a field_my_second_field entry for each run through the foreach loop.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜