6

I am trying to access from views-view-field--title.tpl template to another field...

I have this code:

<?php print $output;
  print $row->{$view->field['field_NAME']->field_alias};
 ?>

But it shows me just a number.. (1,2,3,4,5,....)

Can someone help me?

Thank you!

5

I'd suggest that you enable the Devel module on your drupal site (hopefully not a production version ;-). Once you've enabled that module, you can use the dsm() function, within php tags in your templates to inspect in detail the variables that are provided in each template!

So enable the Devel module, then add the following to your template file:

<?php dsm($view->field['field_NAME']); ?>

Clear your cache and go to a page that contains a view... What the dsm() function should do is output your object in the 'Help' section of your page:

enter image description here

Just click on the object and start inspecting all the fields it has available. You'll see that what it's returning with the 'field_alias' property is just the nid of that node...

Since you didn't specify what you're trying to get with the additional field, I can't be any more specific, but hopefully digging around will let you figure out how to get to the field property/properties you need. Let us know if you figure it out!

p.s. Since the 'title' field template is called for each row displayed in your view, you will get that 'field' object multiple times - once for each time the template was called.

1
  • 2
    Thank you very much! Working. Here is the code if someone need it: print $row->_field_data['nid']['entity']->field_NAME['und'][0]['value'];
    – Dzoni
    Apr 9 '13 at 21:05
2

I had the exact same problem, I inspected the $row variable using this

foreach ($row as $key => $value)
{
   print $key;
   print " : ";
   print $value;
   print "<br>";
}

until I had this

foreach ($row->field_field_link_text[0]["rendered"] as $key => $value)
{
   print $key;
   print " : ";
   print $value;
   print "<br>";
}

Which finally gave me the answer I was looking for:

$row->field_field_link_text[0]["rendered"]["#markup"]
1

I wish I had known about this before :-)

I wish I had known about this before :-)

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.