1

I'm using the views-view-field--field-fieldname.tpl.php to rewrite the output of a specific field in a view. However in this template I'm having trouble referring to the actual field.

I can produce the normal input with

print $output;

However this contains the classes and divs it is wrapped in. Including the default icon that is used to represent it. I'm having trouble producing the specific data of the field. Specifically the url to the file. (It is a file field). Is this possible? I made quite a number of attempts. Below are the attempts I've made that were unsuccessful.

print $fields['fields_field_fieldname']->content;

print $row['fieldname'];

print $view->results->{view->field['field_fieldname']->field_alias}; 

I understand that I could use string replace and regex to extract the data I need $output. If that's the only way to do it, I'll stick to that.

  • Did you try to check available field settings at views ui? – kala4ek May 28 '15 at 15:46
  • In the example replacement patterns I've found [nid] == Content: Nid [field_fieldname] == Content: Icon [field_fieldname-fid] == Raw fid [field_fieldname-display] == Raw display [field_field-description] == Raw description. However referring to those produces nothing – Matt May 28 '15 at 15:54
2

File field has formatter "URL to file", please see this screenshot: views ui, field settings

So finally, in $output will be only url to file.

Also, if you don't want any views default wrappers, you can unselect checkbox in "STYLES" fieldset (see screenshot abowe).

  • when including images, please embed them in the actual answer, not as a link - if the link dies, the image is useless for the future – Geoff May 28 '15 at 18:32

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.