Hi,

After searching the forum, and documentation, I learned that:

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

would print out the field value. My field is "field_rating"

I've tried print $fields['field_rating']->content; & print $fields['field_rating_value']->content; to no avail.

I'm using the views-view-unformatted theme. Any help would be greatly appreciated!
:)

Comments

dawehner’s picture

you can print out the whole $fields array by using

<?php drupal_set_message('<pre>'.print_r($fields, TRUE) .'</pre>');
?>

There you can see all availible variables

Phil Wolstenholme’s picture

Title: Printing single field not working » How to print a single field

For me that just brings up an empty drupal message box with a empty set of

tags inside it.

print $fields['postal_code']->content; doesn't work, neither does:

$data = $row->{$field->postal_code};
echo $data;

I'm trying to echo one single field (the postal_code field) in the header of my gmap view. How could I do this?

I've tried numerous array approaches but haven't yet found the right code. Apologies, because I know this is basically a basic php question, but any help would be hugely appreciated. I have read the Theme:Information documentation, and also Merlin's comments on this thread http://drupal.org/node/286700 - but I still haven't really grasped how to do this.

Phil Wolstenholme’s picture

Sorry to shamlessly bump this when the Views queue is busy, but I'm hoping the solution is just something quick that I just don't know about yet.

dawehner’s picture

could you var_export your $fields, then i could help you quite fast :)

Phil Wolstenholme’s picture

Thanks a lot dereine.

Hmm I feel even more stupid, using the code Var_export: <pre><?php var_export($fields); ?> </pre> gives a NULL result... I'm using it in the header of a page view, with the php filter selected.

dawehner’s picture

could you also try out $row.

I think $fields is not defined there, see documentation in your views tpl file.

Phil Wolstenholme’s picture

Unfortunately the same thing happens with $row... There must be a way to get Views data in the header.

Just to give the issue some context, and maybe to help anyone come up with an alternative solution, I'm displaying a map page made up of a Map View for each venue. Above the map I want to have a link to Google Maps's directions finder, with the destination postcode already filled in. To do this I need to insert a link above the Map View display, and include a view field's data within the link....

Phil Wolstenholme’s picture

Title: How to print a single field » Print content (including data from a View field) above a GMap view

Hi, I've made the title of this issue a little bit more descriptive and general in the hope that someone will be able to help me.

I've got a Google Maps view set up, but I need to print a link (to driving directions) above or below the GMap element of the view. The content printed (presumably in a header or footer) needs to be a postal code, which is one of the fields in the view.

Does anyone know how I would do this?

esmerel’s picture

Status: Active » Closed (fixed)

This issue is a year old, it's likely either resolved or no longer relevant.