3

When using Views, I always use fields instead of content. But I noticed that Views does not show the machine name of a field and it only assumes that you already know it. Is there some other way to find out the machine name?

Knowing the machine name lets me access the field directly like so

print $fields['machine_name_here']->content;
2
  • Where do you need the machine name? In a template?
    – Oswald
    Aug 5, 2011 at 8:55
  • Yes. I need it so I can lay it out like in the sample code above.
    – enchance
    Aug 5, 2011 at 9:03

2 Answers 2

6

Go to the settings page of a view, and click on "Theme information"; then you look at the IDs of each field. For example, if "Theme information" shown this information, then "last_comment_name" would be your machine name.

Field Node: Last comment author (ID: last_comment_name):

3
  • So it is! Sneaky little bastard hiding in the theme info.
    – enchance
    Aug 5, 2011 at 9:23
  • 4
    lol i helped someone yeesssss!!!! 4 years of working with drupal and not knowing a bit of code has finally paid off for me enchance.
    – Reg Gordon
    Aug 5, 2011 at 9:36
  • Haha best comment evaaar!
    – enchance
    Aug 5, 2011 at 11:17
1

If you use the devel module (highly recommended) you could also insert a function to show you all the available fields for the view:

<?php dpm($fields); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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