2

I am trying to define a custom field in D7 view, and I used views_php. Here few variables are available as field tokens, but while using it inside the code, it doesn't return its original value, but does the node id.

Available variables:

  • $view: The view object.
  • $handler: The handler object.
  • $static: A variable that can be used to store reusable data per row.
  • $row: Contains the retrieved record from the database (e.g. $data->nid).
  • $row->nid: Content: Nid
  • $row->field_twitter_page: Content: Twitter Page
  • $row->field_facebook_page: Content: Facebook Page
  • $row->php: Global: PHP
  • $data: Contains the retrieved record from the database (e.g. $data->nid).
  • $value: Value of this field.

I need to fetch the value of "$row->field_facebook_page"; so I wrote:

<a href="<?php print $row->field_facebook_page; ?>"Like</a>

When I click on the "Like" link, the given URL is empty. When I print the variable, I get the node ID.

What am I doing wrong?

3

Start with print_r to see what's available:

<pre>
<?php print_r($data); ?>
</pre>

You will likely end up using $data, something like:

$data->_field_data['nid']['entity']->field_facebook_page['und'][0]['value']

If that doesn't work, take a look at http://drupal.org/node/1140896#comment-5945164

0

Thanks Keva. It works!

<?php 
$node = node_load($row->nid); //loads the entire node values

$fburl = $node->field_facebook_page;
$fburl1=$fburl['und'][0]['value']; 

$twurl = $node->field_twitter_page;
$twurl1=$twurl['und'][0]['value'];
?>

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.