I made a view with a relationship, showing:

  • Title of the node
  • Title of the referenced node
  • Path of the referenced node

These values display as expected, but if I create a PHP field with the following code in the output, it only displays titles.

echo 'Title: '. $row->title.'<br />';
echo 'Title 1: '. $row->title_1.'<br />';
echo 'Path: '. $row->path.'<br />';


  • I don't mean to make things complex, but you should not be using views-php-field for stuff that can be done with regular content fields. And my guess is all of these can be done with content fields. – Steven Sep 11 '13 at 16:26
  • I forgot to mention that I also populate the nid of the node (from #1) in order to create a link to the node that is referenced (#2+3) like "url/to/node?field_reference=[nid]" I thought this can only be done through a php field. Why is it a bad practice? – tobik999 Sep 11 '13 at 21:38
  • You do not need a php field to accomplish that task. Just add the NID, title & aliased path fields to the view, and set them to be excluded from display. Then add a 'custom text' field and use the tokens views creates from the excluded fields to build your output. – Chance G Sep 11 '13 at 21:52
  • Thanks, I did not know that custom text also allows HTML – tobik999 Sep 12 '13 at 8:03
  • Yes. But it will strip inline styles. Be sure to use classes and your themes stylesheet. – Chance G Sep 13 '13 at 6:16

It is a known issue with views_php. You should be able to access the field information through the $data variable though. If you have Devel installed just run dpm($data) in place of your code above and see how to access the field information.

For what it is worth, it is generally considered bad practice to store php code in the database. I would suggest taking a look and seeing if there is any way you can accomplish what you are after with a template file override or some other means. If the only thing you are trying to accomplish is concatenation of those 3 fields with labels, you can do that with a regular views 'custom text' field and the tokens views provides.

| improve this answer | |
  • I added a comment above, could you maybe tell me why it is a bad practice to store php code in the db. For security or performance or both? – tobik999 Sep 11 '13 at 21:39
  • Security is definitely an issue. If you are the only admin and no one else will ever adjust the views or have access to the backend, I admit it is less of an issue. One of the big problems is that it makes debugging a royal pain when the code used to build your site is not searchable. – Chance G Sep 11 '13 at 21:47

I propose you should use either a tpl.php for your view or if you really want to insert code there, do something like:

$node = node_load($row->path); // im guessing it shows you the node id

echo 'Title: ' . $node->title; 
echo 'Path: ' . drupal_get_path_alias('node/' . $node->nid);
| improve this answer | |

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.