Display views row data using PHP Customfield

Public

Thanks to Views Customfield module, you can output php in a view field.

Every row contains its data and the main ID (nid/tid/cid...) in the $data variable. This are raw data, since formatting occurs per row later on the theme level.

It's always usefull to print all the data since keys are very often prefixed (ex : $data->node_title );

Get raw version
php
  1. <pre>
  2. <?php print_r( $data ); ?>
  3. </pre>

$data also contains previous rows data. You can pass data from a row to another by setting a value in $data.

Get raw version
php
  1. <?php
  2. $data->my_value_1 = $value;
  3. ?>

In other row :

Get raw version
php
  1. <?php
  2. print $data->my_value_1;
  3. ?>

If you need to pick several raw $node value, you can use this pattern to load the node one time and store it in $data for later reuse per row. ($data->nid is always present for node based views)

Get raw version
php
  1. $data->n = node_load( $data->nid );

Comments

doubouil's picture

dpm actually output the $data in the $message variable (aka "console" for me). My personnal preference is to have the debug along with the data, for example in a separate column for a table-rendered view, hence the <pre><? print_r( $data ); ?></pre>