Hello all,

I have been searching for days in how to print a single field in views 3.
In views 2 it was print $fields['field_name fo my field']->content;

Now i have managed something like this: print $fields['entity_id_3']->content;

but there must be a better way using the field name no?

any help would be appreciate i also have not found any documentation on how to use variables in views 3

thanks

wolfmarter

Comments

wolfmarter’s picture

I have been trying a new way:
print $fields["field_fileupload"]["de"][0]["description"]->content;

it doesnt work yet but maybe i am on the right way....

maybe it helps someone

i will keep posting...

wolfmarter’s picture

Undefined index: field_fileupload in include()

bdparker’s picture

Try downloading Devel! What people are doing in this thread is the same way I'm doing it, and it's convoluted and difficult. Devel will at least give you the right array path you'll need for each variable. Well... usually. It's resourceful!

jacov’s picture

try this in page.tpl.php:

  print render($page['content']['system_main']['field_example']);

That example works for page.tpl.php, however fields are accessible in different arrays when called from different theme files.

For example, to access a field from profile, on just the profile content page - user-profile.tpl.php , you could use this:

  print render($user_profile['field_example]);

You can use the theme developer module and krumo to see the tpl.php candidates, accessible arrays and more.

JB

wolfmarter’s picture

thank you for the reply.
I have now tried this:
print render($fields['field_fileupload']["de"][0]["description"]->content);

but there is no result not even a mysql warning.

to print out variables in nodes is easy i have been doing that since d7 came out:

echo $node->field_tel['de'][0]["value"];

but i dont understand how to get teh field in a view....

wolfmarter’s picture

object(stdClass)#141 (9) { ["nid"]=> string(2) "14" ["taxonomy_term_data_name"]=> string(23) "Angebote Durcharbeit Q2" ["taxonomy_term_data_vid"]=> string(1) "1" ["taxonomy_term_data_tid"]=> string(1) "6" ["taxonomy_vocabulary_machine_name"]=> string(4) "tags" ["draggableviews_structure_node0_value"]=> string(1) "0" ["field_data_field_fileupload_node_entity_type"]=> string(4) "node" ["field_data_field_user_node_entity_type"]=> string(4) "node" ["_field_data"]=> array(1) { ["nid"]=> array(2) { ["entity_type"]=> string(4) "node" ["entity"]=> object(stdClass)#158 (32) { ["vid"]=> string(2) "14" ["uid"]=> string(1) "1" ["title"]=> string(38) "Red Stag Q2u3 Schwerpunkt Bars u Clubs" ["log"]=> string(0) "" ["status"]=> string(1) "1" ["comment"]=> string(1) "1" ["promote"]=> string(1) "0" ["sticky"]=> string(1) "0" ["nid"]=> string(2) "14" ["type"]=> string(6) "upload" ["language"]=> string(2) "de" ["created"]=> string(10) "1301317654" ["changed"]=> string(10) "1301324979" ["tnid"]=> string(1) "0" ["translate"]=> string(1) "0" ["revision_timestamp"]=> string(10) "1301324979" ["revision_uid"]=> string(1) "1" ["field_fileupload"]=> array(1) { ["de"]=> array(1) { [0]=> array(11) { ["fid"]=> string(2) "12" ["display"]=> string(1) "1" ["description"]=> string(38) "Red Stag Q2u3 Schwerpunkt Bars u Clubs" ["uid"]=> string(1) "1" ["filename"]=> string(42) "red_stag_q2u3_schwerpunkt_bars_u_clubs.pdf" ["uri"]=> string(51) "public://red_stag_q2u3_schwerpunkt_bars_u_clubs.pdf" ["filemime"]=> string(15) "application/pdf" ["filesize"]=> string(6) "348896" ["status"]=> string(1) "1" ["timestamp"]=> string(10) "1301317654" ["rdf_mapping"]=> array(0) { } } } } ["field_user"]=> array(1) { ["de"]=> array(3) { [0]=> array(1) { ["uid"]=> string(2) "17" } [1]=> array(1) { ["uid"]=> string(1) "7" } [2]=> array(1) { ["uid"]=> string(1) "1" } } } ["field_menu"]=> array(1) { ["de"]=> array(1) { [0]=> array(1) { ["tid"]=> string(1) "6" } } } ["field_imageupload"]=> array(0) { } ["field_category"]=> array(0) { } ["field_text"]=> array(0) { } ["rdf_mapping"]=> array(9) { ["rdftype"]=> array(2) { [0]=> string(9) "sioc:Item" [1]=> string(13) "foaf:Document" } ["title"]=> array(1) { ["predicates"]=> array(1) { [0]=> string(8) "dc:title" } } ["created"]=> array(3) { ["predicates"]=> array(2) { [0]=> string(7) "dc:date" [1]=> string(10) "dc:created" } ["datatype"]=> string(12) "xsd:dateTime" ["callback"]=> string(12) "date_iso8601" } ["changed"]=> array(3) { ["predicates"]=> array(1) { [0]=> string(11) "dc:modified" } ["datatype"]=> string(12) "xsd:dateTime" ["callback"]=> string(12) "date_iso8601" } ["body"]=> array(1) { ["predicates"]=> array(1) { [0]=> string(15) "content:encoded" } } ["uid"]=> array(2) { ["predicates"]=> array(1) { [0]=> string(16) "sioc:has_creator" } ["type"]=> string(3) "rel" } ["name"]=> array(1) { ["predicates"]=> array(1) { [0]=> string(9) "foaf:name" } } ["comment_count"]=> array(2) { ["predicates"]=> array(1) { [0]=> string(16) "sioc:num_replies" } ["datatype"]=> string(11) "xsd:integer" } ["last_activity"]=> array(3) { ["predicates"]=> array(1) { [0]=> string(23) "sioc:last_activity_date" } ["datatype"]=> string(12) "xsd:dateTime" ["callback"]=> string(12) "date_iso8601" } } ["cid"]=> string(1) "0" ["last_comment_timestamp"]=> string(10) "1301317654" ["last_comment_name"]=> NULL ["last_comment_uid"]=> string(1) "1" ["comment_count"]=> string(1) "0" ["name"]=> string(10) "wolfmarter" ["picture"]=> string(1) "0" ["data"]=> string(282) "a:9:{s:16:"ckeditor_default";s:1:"t";s:20:"ckeditor_show_toggle";s:1:"t";s:14:"ckeditor_popup";s:1:"f";s:13:"ckeditor_skin";s:4:"kama";s:15:"ckeditor_expand";s:1:"t";s:14:"ckeditor_width";s:4:"100%";s:13:"ckeditor_lang";s:2:"en";s:18:"ckeditor_auto_lang";s:1:"t";s:7:"overlay";i:1;}" } } } }

wolfmarter’s picture

I have found a way to navigate thorought the arrays:
print $fields['entity_id']->content;
print $row->_field_data['nid'] ["entity"]->field_fileupload["de"][0]["filesize"];

but there must be an easier way not?

anyone?

andrea.cavattoni’s picture

crazy D7 Stuff...

krymp’s picture

I have been running in to the same issue: I used to create a views template,
for example: views-view-fields--video--block-1.tpl.php

Then in there I would give my custom css wrap around the field code like this

Now when I try to put in the new views template, I get an error:
Notice: Undefined variable: fields in include() (line 52 of /templates/views-view--message-post--block.tpl.php).
Notice: Trying to get property of non-object in include() (line 52 of /templates/views-view--message-post--block.tpl.php).

Does anyone know how to bring over the fields manually

krymp’s picture

This was solved

W.M.’s picture

Would you please explain more, what solved that ?!

flavio_tito’s picture

...

knalstaaf’s picture

Maybe you can find it there, if it isn't here.

rohr’s picture

Thanks to @wolfmarter.

For anyone else that is about to throw something trying to figure this out ... I'm not sure if this code is ideal, but it works. This example pulls the nid of a node reference field. I am using this in a views field tpl.php file.

$data = $row->_field_data['nid']["entity"]->field_story_1["und"][0]["nid"];
print $data;

Use this first to follow the object down the line:

drupal_set_message('<pre>'. print_r($row, TRUE) .'</pre>');
knalstaaf’s picture

<?php print $view->render_field('field_your_field_name', $id);?>

delacosta456’s picture

You save me from long days searching for this..
Worked for me too..

Many thanks

madan879’s picture

Thanks @knalstaaf..

print $view->render_field("body", $view->row_index);

Instead of $id use $view->row_index.. As you mentioned code is worked me..

efes’s picture

Saved my day!

------
by eFeS

alex72rm’s picture

It doesn't work with an editable field (from "editable views" module)

Alessandro Bonelli

delacosta456’s picture

You save me from long days searching for this..
Worked for me too..

Many thanks

uniweb’s picture

one more day saved, thanks so much