Advertising sustains the DA. Ads are hidden for members. Join today

On this page

Output code

Last updated on
11 December 2018

This is documentation for Drupal 7, which is no longer supported. Learn more and find resources for Drupal 7 sites

The Views PHP field contains a section labelled Output code where you can create output to be displayed by the field. The content starts in HTML mode and you can add PHP using the PHP element.

The following example prints a node title from a node row.
<?php print $row->title; ?>

The following example prints a node title from a node row within a heading.
<h2><?php print $row->title; ?></h2>

$value

Views PHP has a section to generate a value that will be returned to Views. The Output section follows the Value section and, in my test, the Output section shows the value from the Value section as $value. I can display $value in HTML using code such as the following.

<div style="background-color: #ccccff;"><?php print $value; ?></div>

The value is also added to $row as $row->php, something you can display as follows.
<div style="background-color: #ccffcc;"><?php print $row->php; ?></div>

Help improve this page

Page status: No known problems

You can: