0

I'm trying to get a specific field number in my "views-view-fields--news.tpl.php". Right now it's like this :

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

I've tried to do something like this :

<?php print $fields[0]->content; ?>

But it doesn't seem to works and Google doesn't care about my problem.

Can you help me figure this?

apaderno
  • 28,547
  • 16
  • 75
  • 90
Chololoco
  • 3,140
  • 1
  • 21
  • 24

2 Answers2

0

You have to use the field name instead. Try to use

<?php var_dump(array_keys($fields)); ?>

to find the one you need

DuaelFr
  • 395
  • 1
  • 5
0

This is my individual field tpl file name in theme folder

views-view-field--field-fba-value.tpl.php

where "field-fba-value" is my field name. so don't need to use $field variable here and iterate it through loops. I just use $output variable that contain the current value of the field.

Draw back of this approach is if you want to put styling of each field then you need to create those many tpl file. But if you have one or two field to make styling on it then go with this approach.

Vikas Naranje
  • 2,350
  • 5
  • 30
  • 40