1

Inside views-view-list.tpl.php there is a loop like this:

<?php foreach ($rows as $id => $row): ?>
  <li class="<?php print $classes_array[$id]; ?>"><?php print $row; ?></li>
<?php endforeach; ?>

I want to be able to access the actual values of the fields inside each item, rather than passing off the rendering of the html to views-view-fields.tpl.php.

In pseudocode, I would like to do this (THIS CODE DOES NOT WORK):

<?php foreach ($rows as $id => $row): ?>
  <?php print $row->$fields['field_my_field_name']; ?>
<?php endforeach; ?>

<?php foreach ($rows as $id => $row): ?>
  <?php print $row->$fields['field_my_second_field_name']; ?>
<?php endforeach; ?>

Would I actually use the $row object, or would I use something else?

2

views-view-list.tpl.php file it's a view template to display a list of rows, not fields.

Theming only fields:

<?php foreach ($fields as $id => $field): ?>
    <li><?php print $field->content; ?></li>
<?php endforeach; ?>

* file: views-view-fields--[view name]--[display].tpl.php

Theming the whole output:

<div class="<?php print $classes; ?>">
    <?php foreach ($view->style_plugin->rendered_fields as $delta => $item): ?>
        <li><?php print $item['field_my_field_name']; ?></li>
    <?php endforeach; ?>
</div>

* file: views-view--[view name]--[display].tpl.php

3

took me a while to work this out so sharing the solution i used.

<?php foreach ($rows as $id => $row): ?>
    <?php print $view->render_field('field_my_field_name', $id);?>
<?php endforeach; ?>

<?php foreach ($rows as $id => $row): ?>
    <?php print $view->render_field('field_my_second_field_name', $id);?>
<?php endforeach; ?>
  • Why is this not working! I am wondering how it got three votes – Md Eqbal Ahmad Dec 28 '16 at 7:36
1

There is a $view variable inside most Views templates that contains the entire View Object. Inside of it, you can access the raw results via $view->result which is basically an array of the rows. Throwing in a drupal_set_message('<pre>' . print_r($view->result, TRUE) . '</pre>') or equivalent will give you an idea of what you have to work with.

0

The simplest way is : $fields["field_name"]->content; Where field_name -> cck field name.

Hope that will help !!

Cheers ! Raj

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.