The problem is probably that I'm assuming this module does something that it wasn't designed to do, but it would really help if you could write a couple of sentences explaining just exactly how this works.

I've installed the module and activated it. Isn't something supposed to happen now? I guess I expected to see some new options in the Views workflow. Specifically, I was hoping that the Fields I selected for display would have input options that allowed me to enter additonal PHP or HTML and thus alter what is generated for display by the view.

But I don't see anything different in my Views interface. Can you clarify how this works? Is there some additional configuration I need to do?

Members fund testing for the Drupal project. Drupal Association Learn more


cbroberts26’s picture

Status: Active » Closed (fixed)

Ok, I think I get it now. As I suspected, the problem was that I was expecting something different from what the module provides.

The custom fields appear on the list of Fields to add to your view. They are not added as new input options for existing Fields. You can create a new, custom Field and put your PHP code in it, but you can't take an existing Field, like Node:Teaser, and throw in some PHP code to modify what is displayed.

Or can you? Ah ha! If you add the custom PHP field after, say, the teaser field, then set the teaser field not to display, you can grab the teaser text from the SQL results using $data->node_revisions_teaser and embed the teaser text in your PHP and go to town! Great! This works a little differently than I expected, but it does what I need.

For anyone struggling as I was:

1. When creating a view and adding Fields to the view, the Fields available will include custom fields like Customfield: PHP Code. Add one of these fields after you've added the regular content fields like Node:Teaser (if you want to modify the way the teaser text is displayed by embedding PHP in the view output).

2. Set the Node:Teaser field to Exclude from Display if you want to display the teaser text only in the custom field where it is modified with PHP code (or HTML code if using Customfield: Markup).

3. To grab the teaser text and display it in the custom field, use $data->node_revisions_teaser in your PHP code. So it would look something like this:

     echo "This is the teaser text from the database: ".$data->node_revisions_teaser;

You can see what data is being returned from the SQL query and what the variables are being named by looking at the SQL string displayed at the bottom of the Views > Edit page after you've updated after adding a Field. You'll see variable names like node_title and node_created depending on what fields you added to the view.

And now I imagine you can do almost anything to the display.

Obviously most of you understood all of this from the beginning and didn't need anybody to spell it out, but I assume I'm not the only one struggling to figure out how all of this Drupal stuff fits together while still trying to meet deadlines. Hopefully some will find this helpful.

whan’s picture

Thanks, the information helped me a lot.

rashad612’s picture

Title: Could you provide a little more information? » Theming

How can I override the Views Custom Field in tpl page ?

kvvnn’s picture

To find out what fields are accessible you can use:

print var_export($data, TRUE);
ecksley’s picture

Version: 6.x-1.x-dev » 5.x-1.x-dev

Great module!

I wanted to use it as a means to strip the "The" from the front of some node titles so that my Views page can sort them alphabetically without it.

However, I don't see a way that a View Custom field can be used as a sort criteria? Is that correct?

kvvnn’s picture

Polo’s picture

You are my savior!

nadav’s picture

hello :)

First of all, like all the others, but still, in a very spacial way, thank you for this amazing module, I just found it and I'm thrilled about it. So thank you!

I'm working on this view now that has three fields as grouping field and I'm using Custom Field for merging them to the same field. First two are text fields and work very good,
the third field is image_field and for some reason it is not showing. I am not so good with php yet (and I wonder if this is why it's not working.. hmm ;) ).
this is my code

<img src="<?php 
echo $data->node_data_field_image_cache_field_image_cache_fid?>"/>

this is the fields information that I get:

stdClass::__set_state(array( 'nid' => '1', 'node_type' => 'product', 'node_vid' => '1', 'users_name' => 'admin', 'term_data_description' => 'description text', 'term_image_tid' => '1', 'term_data_name' => 'name text', 'term_data_vid' => '1', 'term_data_tid' => '1', 'node_data_field_image_cache_field_image_cache_fid' => array ( 0 => array ( 'fid' => '3', 'list' => '1', 'data' => 'a:10:{s:3:"alt";s:0:"";s:5:"title";s:0:"";s:8:"duration";i:0;s:6:"height";i:22;s:5:"width";i:35;s:18:"audio_bitrate_mode";s:0:"";s:18:"audio_channel_mode";s:0:"";s:12:"audio_format";s:0:"";s:13:"audio_bitrate";i:0;s:17:"audio_sample_rate";i:0;}', ), ), )) 

thank you upfront :)

jcroft’s picture

Version: 5.x-1.x-dev » 6.x-1.0

This worked for me.
Note in my case the cck field was named "image_1"

$file = field_file_load($data->node_data_field_type_field_image_1_fid);
$imgPath = $file['filepath'];
echo "$imgPath";
colemanw’s picture

Just wanted to say thanks for an invaluable little module. Using the custom php field you provided is the only way I have been able to include comments in a view of nodes with row-style: fields. Here's how I did it:

  1. Create a node view to show the nodes you want. Set row-style to fields, and include the fields you want. For my blog view, it shows nodes of type 'blog' and the title, author, headshot, and content fields.
  2. Create another view (not just another display, you need a whole extra view because this one is for comments). Name it comment_view or something. Give it the relationship "Comment: Node" and the argument "(node) Nid" and set the row style either to full comment (to show comments exactly like everywhere else in drupal) or create custom fields to your hearts desire.
  3. Go back to your node view, and add one more field, this time a custom PHP field provided by this module. Type in this php code:
    print views_embed_view('comment_view', 'default', $data->nid); 

    Substitute the actual name of your comment view for 'comment_view' if you named it something else

And viola, you now have a display of both nodes and comments that is 100% customizable using the power of views.

PS. I was surprised there wasn't a more straightforward way to do this. If anyone knows of one, please feel free to enlighten me.

PPS. Of course, if you don't require the 'fields' row-style, there are many more options for achieving this, including just clicking the "show comments" box in views or (if you want to customize the comments, i.e. by limiting the number shown, fields, etc) doing step 2 above and then embedding that view in the template file of the node-type in question. You can get around having it show up in the actual node page by using the teaser view instead of the full view.

benjah’s picture

#9 above worked like a charm!!!!
Thanks jcroft!

Feonyx’s picture

Thank you so much for this! I was racking my brain as to how I would convert a profile variable stored in the database to a different value.

I simply added the filter for the profile refid. Made it "Exclude from display" and then added a "Customfield: PHP code" as such:

    $hexID = dechex(intval($data->profile_values_profile_refid_value));
    print strtoupper($hexID);

And voila it converted the string to hex. Thanks again.

ealtman’s picture

Just want to say, this is my favorite module at the moment. Thank you!

Jerome F’s picture

@cbroberts26 in #1
you can't take an existing Field, like Node:Teaser, and throw in some PHP code to modify what is displayed

I think that's more what custom formatters does.

Jerome F’s picture


I have nearly the same question as in #8,
the code in #9 returns the path to the original file, how is it possible to get the path to one specific imagecache preset image ?

benleivian’s picture

Amazing, thank you!

I was able to get gravatars to display in a recent comments view like so"


if ($data->users_comments_picture) {
  echo theme('imagecache', 'user-tiny', $data->users_comments_picture, '', '');
} else {
  $email =  $data->comments_mail;
  $default = "";
  $size = 20;
  $grav_url = '' . md5( strtolower( $email ) ) .
  '&size=' . $size;
  echo '<img src="' . $grav_url . '" width="20" height="20" alt="" />';

this_is_it’s picture

great module.

timtunbridge’s picture

Could someone give me a pointer on how to access a field outside of node please. The only fields that I see returned by print var_export($data, TRUE) are those contained in node, but I want to access fields from other tables that are within the view.

In the attached screenshot I want to be able to access selling_price and list_price. I know these are in the uc_product table but as you can see these are not listed in the select statement, hence I do not know how to refer to them.


colemanw’s picture

In my experience, any field you add to the "fields" list will become available in $data. If you do not wish the field to print, you can choose the "exclude from display" option.

timtunbridge’s picture

Thanks for coming back to me colemanw.

I still cannot get the product fields to list (I want to be able to reference them in order to create my custom field). However I have found a workaround by explicitly loading the product node first in my custom field and then extracting them from there.

Cheers Tim

 $list_price = number_format($nd->list_price,2);
 $sell_price = number_format($nd->sell_price,2);
 if ($nd->sell_price < $nd->list_price ) {
    print '<span class="regular-price">Regular Price </span><span class="price-strike">' . $list_price . '</span><br /><span class="special-price">Special Price ' . $sell_price . '</span>';
 else {
    print '<b>Selling Price ' . $sell_price . '</b>';
captaindav’s picture

See this post in the View Slideshow Issue Queue for an example of how to use Views Custom Field to conditionally combine two View fields into one:

matt2000’s picture

Title: Theming » Basic usage information

Reverting back to a descriptive title. Thanks, cbroberts26 for documenting your experience.

Drupal webdesigner’s picture

Great post thanks helpt me a lot.

alanom’s picture

Status: Active » Closed (fixed)

re. "@Tim
In my experience, any field you add to the "fields" list will become available in $data..."

Several types of field, including Global Custom Text and Lightbox triggers, don't show up in a print var_export($data, TRUE); - nor do they show up in a var_dump or even a print var_dump(get_defined_vars()); - How do we find out how to call these?

It seems the various $data->... exports show fields taken straight from node or CCK fields, and don't include fields generated entirely by Views itself. Googling just gives the fields in other contexts (e.g. $handler->display->display_options['fields']['nothing'] - not appropriate here)

Being able to use PHP on fields that have already been combined the normal way would be brilliant, and would make lots of sophisticated operations simple. But how do we find out how they are named? This would be massively valuable reference information.

They must be retrievable in there somewhere, else the replacement patterns wouldn't be able to access them. But where, and how do we find out? I've even tried looking back through Views code to see how the replacement patterns are implemented, looking for a PHP variable to call - no joy.

Thanks in advance!

alanom’s picture

Status: Closed (fixed) » Active

Changing to 'active' as this thread seems to have become the main basic documentation for the module, not just a support request.

If we can clear up ways to load data that isn't obviously available in the $data object, such as the fields mentioned above, that would be good documentation, since standard Drupal methods like using arrays in the $node object don't work here. has some info on how tokens could potentially be used, but this seems a very heavy and limited work-around - particularly as token filter doesn't currently work with node tokens. Perhaps more crucially, it has the same problem - there doesn't seem to be any way to access Global Custom Text fields with tokens, either, since they don't exist outside of views.

alanom’s picture

Status: Closed (fixed) » Active

Found it! The best way to get field data into PHP customfields when $data isn't appropriate is:

1) On Views Custom Fields 6.1, hand-patch the file views_customfield\includes\ replacing the method function render($values) from line 55 using the bartclarkson's code snippet in

2) Use the replacement token as you would in other Views fields, as a php string. For example, to print a typical lightbox trigger field, you'd use print '[lightbox2]';

As well as making it possible to use Views-generate fields, this method also preserves Views formatting and processing for various fields, particularly filefield FID based fields, such as imagefield images complete with alt text, and embedded video. This ensures neat integration with Views-integrated modules.

JimNastic’s picture


Is it possible to use views_embed_view() within a custom field as a means of achieving sub-views? I'd like to create a list of "children links" which appears when the user hovers over any of the teaser images returned by my view.

If this doesnt work with custom fields, can anyone suggest another approach?


soulston’s picture

you can also use:


to output the available fields in a nicer way.

(Thanks for spotting the typo juanlacueva)

colemanw’s picture

@JimNastic Please see comment #10

juanlacueva’s picture


you missed the "$" before data

juanlacueva’s picture

Can I make mysql queries within a Custom PHP field?

What would be the appropriate way?

I guess putting mysql_connect(...) and mysql_query(SELECT...) wouldn't be best practice at all.

I have a multiple item field in content. This multiple items in one field are nids. I want to get the titles of those nids inside a field.
Using arguments I managed to get the nids (excluded from display) but the only way I can think to retrieve their titles is to query the db. IS there any other way?


kvvnn’s picture

Just use db_query and its friends in your php statement.

kunago’s picture

I thought I could share a node counter for taxonomy terms. Might be of some use for somebody.

  $counter = NULL;

  $sql = "SELECT t.nid FROM {term_node} t LEFT JOIN {node} n ON t.nid = n.nid WHERE tid=%d AND n.status = '1'";
  $results = db_query($sql, $data->tid);
  while ($result = db_fetch_object($results)) {

  print $counter;
jrivelli’s picture

I created a custom node.tpl.php page and am displaying cck fields with print $node->field_extras[0]['view']
and works just fine. However, I have a cck field that is checkboxes with users able to select multiple values and the above php only displays the first value. I can do print $node->field_extras[2]['view']
(notice number change) and it will display different fields in the checkbox list. However, I know there is a better way than to lis tout all these, especially since it leaves blank spots if the user hasn't checked one of the options. Any tips? or should I use this module?

cccarlington’s picture

Why not just loop through the array and only print the values that exist.
I am not much of a php coder but something like this.

$counter = 0;
$max = 4; //however many values the user can select/click
print "<ul>";
while ($counter < $max) {
  if ($node->field_extras[$counter]['view'] != "") {
    print "<li>" . $node->field_extras[$counter]['view'] . "</li>";
print "</ul>";

There is probably a more elegant way to do this

kunago’s picture

What about this one? Feels to be a little bit more automatic to me as there is no need to set the "max" value.

$counter = 0;
print "<ul>";
while ($counter <= count($node->field_extras)) {
  if (empty($node->field_extras[$counter]['view'])) {
    print "<li>" . $node->field_extras[$counter]['view'] . "</li>";
print "</ul>";

I am not sure what values the "$node->field_extras" could have therefore what could also work for line 5 is

  if (isset($node->field_extras[$counter]['view'])) {

or as suggested

  if ($node->field_extras[$counter]['view'] != "") {
jrivelli’s picture

Thanks for those suggestions! I got it working, the code is VERY similar if not the same, as your second example. :)

shriji’s picture

Subscribing....helpful post

msjones design’s picture

thank you, subscribe.

HippoOnDiet’s picture

Hi Guys,

I need a hand on how do I pull Location (module) information from a view?

At the moment my current view have field: Location and related to content: home address.

When I run print var_export($data, TRUE); I get this info:
'location_node_data_field_member_profile_resaddress_lid' => '9',
On d6_location tid 9 - it contains the address for this employee

However I don't have much clue what query or what php line do I need to write so it will show the address.

Your help is much appreciated :)

I found my alternative workaround by using Bert's code on:

charles.holtzkampf’s picture

Wondered if someone could assist me, I have no PHP knowledge so im struggling a bit.
I have installed the - To Do List Module -
I created a view with the following fields:
User: Uid (excluded from display)
Node: Title
To do list: Deadline
To do list: Priority
To do list: Start date
To do list: Status
To do assigned users: Assigned user ID (excluded from display)
To do list: Buttons (excluded from display)
Customfield: PHP code

The following Tokens/Replacement Patterns are available based on the above fields

* [uid] == User: Uid
* [title] == Node: Title
* [deadline] == To do list: Deadline
* [priority] == To do list: Priority
* [start_date] == To do list: Start date
* [item_status] == To do list: Status
* [uid_field] == To do assigned users: Assigned user ID
* [buttons] == To do list: Buttons
* [phpcode] == Customfield: PHP code
* [markup] == Customfield: Markup

What I would like to accomplish is:

As, the button field has been excluded, I am trying to use the Customfield, to display that button. But only display that button if the current user is the author of the To Do node.

What ive aded to Customfield PHP code

global $user;
if ($user->uid == $data->uid_field)
print '[buttons]';

What's happening
Nothing displays using the above code.

I know the [buttons] token works because when I use the following code, it displays the button.

print '[buttons]';

So I assume something needs to be added so that the system can decide whether the current logged in user is the author of the node. Both the [UID] & [UID_FIELD] always display the same value if I ouput it, so I thuogh that would work but it doesn't.

Any help would be very much appreciated.


sanguis’s picture

this made my life really easy: I needed to make a custom display using other $data values
so the first thing I did was make a custom php field with the label 'views data' as a value I gave it


(one could also use dprint_r(), but I prefer to have my data per recored with the record)
Then I started adding the other fields that needed. as I populated the view my dump populated with data that I could use in my custom field.
it looked like.

stdClass Object
    [nid_1] => 33667
    [node_data_field_book_image_field_book_image_fid] => 804
    [node_data_field_book_image_field_book_image_list] => 1
    [node_data_field_book_image_field_book_image_data] => a:2:{s:3:"alt";s:60:"Roto quidem populus typicus mauris adipiscing dolus dolore. ";s:5:"title";s:84:"Venio tum validus qui sed decet valetudo erat. Elit minim nisl damnum letalis tego. ";}
    [node_type] => book
    [nid] => 33667
    [node_vid] => 33667
    [node_title] => Uxor Ymo

Just a thought,hope it helps

charles.holtzkampf’s picture

global $user;
if ($user->uid == $data->to_do_assigned_users_uid)
print '[buttons]';
slavojzizek’s picture

Is there any way to use this to show if an Ubercart product sizes are in or out of stock?

On my view i want it to have a field - in stock, or out of stock.

Then, the calculation is - if size a, b, or c have anything in stock say "In stock", and if they are all 0 then say "Out of stock".


If it just could output a list of sizes with in/out of stock under the product that would be fine too.

Product name
size 1 - in/out stock
size 2 - in/out stock
size 3 - in/out stock

uc_views gives me a row for each SKU and its stock, so if I set that to "not display" but use views_customfield, I was hoping I could work with the data.

hoZt’s picture

Slavojzizek, what if you set the view to output as a node type and then create a theme override the node probably using node-product.tpl.php. Then you could have full control of how each product is displayed.

slavojzizek’s picture

Found this to be useful:

But, ended up using the uc_views module, added stock as a field (hidden). Added custom views field of:

IF ($data->uc_product_stock_stock > 0) { 
  print "In Stock"; 
  print "Out of stock"; 

Then, I used the viewsfield module to make the view a CCK field on my product page, passing the NID as an argument.
Used Display Suite to show the field in the right spot.

thepuzzlemaster’s picture

Issue tags: +CCK, +customfield, +mathematics, +sum

Here is what I'm trying to do. I have a view that sets up an invoice. Each invoice contains a variable number of products. From 1-20 we'll say. I currently have the invoice displaying correctly all the information about the products (an image, dimensions, price, title, etc...) but what I need now is a "total price" of all the products.

The way I had thought would be best to do this, is to create 2 attachments. The first one displays all the product info in a table. And the second attachment appears right below it, with the same product info excluded, so the "price" of the products is available to my customfield. I'm not very experienced with PHP and my problems are stemming from 2 things. One, is how do I only have this total price appear once, when if I add it as a field, it will want to display once for each product. And two, how do I add the prices of all the products up to display as the total cost?

I use a relationship to reference the products associated with the invoice. When I put "print var_export($data, TRUE);" as the value in my custom field, I can see that the price field comes back as this:
'node_node_data_field_pieces_node_data_field_main_image_field_price_value' => '8000',

Can't seem to find any help on this, and using a custom field, as opposed to view_calc seems like the cleanest, and most customizable solution.

Any help is greatly appreciated!


dadderley’s picture

Thanks for this module.

I found a really cool use for this module.
I have a view set up using the gmap display.
In the info window, I am displaying small .swf file that pulls data from another db.
I needed to pass the .swf a FlashVars that has the node authors name in it.

I had a problem in that I could not do this as a straight cck field where I can use php to grab the author's name.
The code below works nicely in a node, but not in a view. PHP will not work in this context and it is not a node.

	//print author of the node
	print $node->name;

I tried rewriting the field and using a token for the user.
This should work, but when you do the re-write it strip out the <object> and <embed> tags.
The same with the Global custom text field.
Running out of options here.

So I found this module and this thread.
I put a field in the display for User: Name (shows the node author) and excluded it from the display.
Then I created a "Customfield: PHP code" and put the embed code into this and then used PHP to write in the the FlashVars.
It works very nicely.

// The code below embeds an swf file
// It uses php to write in the flashvars
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase=",0,0,0" width="217" height="189" id="my_flash" align="middle">
				<param name="allowScriptAccess" value="sameDomain" />
				<param name="allowFullScreen" value="false" />
				<param name=FlashVars VALUE="my_flashvars=
				<?php // gets node author name from view
				print $data->users_name;
				<param name="movie" value="" />
				<param name="quality" value="high" />
				<param name="bgcolor" value="#ffffff" />	
<embed src="" FlashVars="my_flashvars=<?php // gets node author name from view
				print $data->users_name;
				?>" quality="high" bgcolor="#ffffff" width="217" height="189" name="my_flash" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="" />
iantresman’s picture

This didn't work for me, and gave me an error (does the dsm function belong to a required module?


But this worked OK, though I added HTML <pre> tags to improve the layout.

print var_export($data, TRUE);
iantresman’s picture

Is it not possible for Views Custom Field to provide a list of available variables itself? The rewrite field option offers a list available tokens, the Content Templates (Contemplate) module has a brilliant option, to display all the available variables for its templates.

So could Views Custom Field have a pop-up, or collapsible section, which lists the PHP variables available for to the customer field.

As a non-PHP programmer, this is the hardest part of creating a field.

Update 11:25pm

Looks like someone has already made this suggestion in this post "Display $data object in a collapsed fieldset on view edit form"

Volh’s picture

Hi, anyone can help me with a question about drupal...?
I need an example with how to use custom fields
can someone support us?

core44’s picture

I've just used a custom field to make the email address of a user profile view to not be publicly displayed if the user chooses to hide it with a checkbox on the profile form. Use with caution.... I have no php skills and rely on hacking and pasting and this is my first drupal website, so please excuse if this isn't the kosher method, but it seemed to work for me.

in the profile settings add a new checkbox field with something like "Please check box to make email private". In your views view for profiles, add the following php code to your views custom field.

if ($data->profile_values_profile_private_email_value > '0') {
    print "User email - Private";
else {
        echo $data->users_mail;

Obviously substituting 'profile_values_profile_private_email_value' with the ID of your checkbox field (you can find this value from the 'Query' output below the view preview. Also substitute 'User email - Private' with the message you wish to display in place of the email if its hidden. "user_mail" I think is the default for the user email address, I guess you could substitute this for any field available that you need to hide with the checkbox.

Hope this helps someone.

EDIT:I've just noticed that for this to work you must have the email field and the field you've created as the checkbox both available to views as fields. You can select these fields to be excluded from display so it wont actually affect the display of the view.

core44’s picture

ok... In addition the above, I've also noticed that the output of this field is not an active mailto link (this is an option when showing the email as a standard field in views). So I've amended my hack from above to wrap the email address in a mailto link making it active in the view.

$email = $data->users_mail;
if ($data->profile_values_profile_private_email_value > '0') {
    print "User email - Private";
else {
        echo "<a href='mailto:$email'>$email</a>";
franso’s picture

Hi Tim

Maybe you can help me out I am also using Ubercart.
I am using this code here in node-product.tpl.php wich is working fine.

<?php if ($node->sell_price < $node->list_price) {
     print '<div class="upprunalegt-verd">';
     print $node->content['list_price']['#value'] ;
     print '</div>';
     print '<div class="tilbods-verd">';
     print $node->content['display_price']['#value'] ;
     print '</div>';           
} else {
            print $node->content['display_price']['#value'];

But I don't know how I can use the same code in Customfield with PHP.
My PHP knowledge is very limited.

Cheers Franz

WigglyKoala’s picture

Howdy, I have a view which is of several content types and filtered by taxonomy. The field is node title. One of my content types is "document" simply a filefield and node title. How can I get my view to turn the node title of these content types to be fid links? so that clicking on the title takes to directly to the pdf document not the node.

I've tried doing this but it only works when theming a single view, I need it for all views... so I think I need to turn to this module but my PHP is rubbish.

"Monkey see monkey do but monkey can't figure it out for herself!"

WigglyKoala’s picture

Ok figured it out, was having a moment obviously!

if ($data->node_data_field_fileupload_field_fileupload_fid) {
   print '[field_fileupload_fid]';
} else {
print '[title]';

is all i needed. fileupload is the name of my file field


this helped to figure out what i needed to input.

AAbhishekk’s picture

It is really a savior..
Embed Drupal Views Using PHP

$view = 'gallery_tab_theatre';
$view = views_get_view($view);
$arg = $view->render_field('title', 0);
print $arg;
sittard’s picture

Great Module.

- franso (#54) use the following:

if ($data->uc_products_list_price > $data->uc_products_sell_price) { 
  print '<span class="was-price">'.uc_currency_format($data->uc_products_list_price).'</span>'; 
  print uc_currency_format($data->uc_products_sell_price); 
else { 
  print uc_currency_format($data->uc_products_sell_price); 
hartogsmith’s picture

thanks for this module. trying to sum one field in a view with this and getting stuck - does anyone have an example of how this can be done?

sanguis’s picture

please post what you have in your field now. so that we can trouble shoot it.

joaomachado’s picture

I have a simple date field in a view, I created a Views Custom Field to calculate the days since that date (today minus the date).
Only with a date of 02/09/2011 it displays 15017, it displays this value regardless of the date, so obviously I am not doing something correctly.

Any ideas?

$today = strtotime("today");
$startDate = strtotime($data->node_data_field_repairdate_repair);
printf("%d", round(abs($today-$startDate)/60/60/24));

PHP 5.2.16

jthomasbailey’s picture


Eaglecanada’s picture

to #56 WigglyKoala:

I use your code, but it seems not working. it seems doesn't pulling out the value from $data->node_data_field_file_field_file_fid. Even though there is a file attach tot he node, it still link the node title to the node link instead of the attachment. on the view, if I click on the next page, it shows an error:Undefined property: stdClass::$node_data_field_file_field_file_fid in __lambda_func()...

anything I am missing?

if ($data->node_data_field_file_field_file_fid) {
	 print '[field_file_fid]';
} else {
       print l($row->title, 'node/'.$row->nid, array('html'=>TRUE));

aLearningGuy’s picture

Here's a superbasic video tutorial

arpas’s picture

If you want to use Replacement patterns, you can use solution provided by bkyan.

Aal’s picture

$data returns NULL

What am I supposed to do now?

Abeaudrian’s picture

I have a content type called 'company profile' and another content type called 'current promotions' which both share a file field called "comp_photo"

I want to output the company photo field which has multiple images attached to this field, in a view of style 'grid'. I am currently getting a few blank fields in between the out put when the query is executed. This output from the query is returned based on a an argument which is based on a 'user id from the url' which evaluates based on the node author.

I am using an image cache preset called 'recent_items_photos' to resize the images returned from the query. My challenge is that I do not know how to plug these requirements into the views custom field to get the necessary results.

Can someone please assist me?

The out put from the current query in view is:

SELECT node.nid AS nid, node_data_field_comp_photo.field_comp_photo_fid AS node_data_field_comp_photo_field_comp_photo_fid, node_data_field_comp_photo.field_comp_photo_list AS node_data_field_comp_photo_field_comp_photo_list, node_data_field_comp_photo.field_comp_photo_data AS node_data_field_comp_photo_field_comp_photo_data, AS node_data_field_comp_photo_delta, node.type AS node_type, node.vid AS node_vid FROM node node INNER JOIN users users ON node.uid = users.uid LEFT JOIN content_field_comp_photo node_data_field_comp_photo ON node.vid = node_data_field_comp_photo.vid WHERE (node.type in ('company_profile')) AND (node.status <> 0) AND (users.uid = 119)

Please note that the user id will not be always 119. However this will be determined based on who the node author of the node being viewed is, and the main reason I am doing this is to get around the view returning empty rows in the display. See attached image. I wish they were an easier way around this challenge.


Adrian Millington

arpas’s picture

debug a view of other style. that html code is generated?

alice-kahn’s picture


I've a content type called "Profession" with some cck checkbox (YES/NO) fields for example;

risk runner: YES/NO
risk maker: YES/NO

risk runner: YES/NO
risk maker: YES/NO

I'm trying to create a view based on these checkbox (yes/no) fields. I've added NodeTitle and all these fields in a view. I've also added Customfield: PHP code with following code:

if ($data->field_dip_riskrunner_value = 'yes') { 
   print ("Only local images are allowed.");
  print ("Only local images are allowed.");

if ($data->field_dip_riskmaker_value = 'yes') { 
   print ("Only local images are allowed.");
  print ("Only local images are allowed.");

elseif ($data->field_dip_riskrunner_value = 'yes') && ($data->field_dip_riskmaker_value = 'yes')
  print ("Only local images are allowed.");

Its not working for me with this code. Can some one please help me with this code?

Thanks in advance,


arpas’s picture

I suggest to check values of $data->field_dip_riskrunner_value, $data->field_dip_riskmaker_value by printing. if you get missing values, then try contemplate module to understant who variables you must to use.

alice-kahn’s picture

I have tried this code as well but again no luck. Can anyone please help me????

if ( $data->field_dip_riskrunner_value == 'yes' ) {
   print ( "Only local images are allowed." );

else {
   print ( "Only local images are allowed." );

if ( $data->field_dip_riskmaker_value == 'yes' ) {
   print ( "Only local images are allowed." );

  // do nothing

if ( $data->field_dip_riskrunner_value == 'yes' && $data->field_dip_riskmaker_value == 'ja' ) {
   print ( "Only local images are allowed." );

  // do nothing
arpas’s picture

First suggestion - print $data->field_dip_riskrunner_value, $data->field_dip_riskmaker_value values. And post result.

francis55’s picture

@cbroberts26: Thanks for writing the introduction documentation of this fabulous module

whan’s picture


agalligani’s picture

Nothing short of AWESOME!

agalligani’s picture

.... but.... if I want to look at User:Roles Roles how can I do this? I don't see it in the list of variables...

agalligani’s picture

I figured it out yesterday. I needed to know if the individual who created the node was an "expert". For this I had created a role called expert so of course I had to assign that role to the users who were designated as experts.

So I created a Customfield and placed the following code in it:

  $role = db_result(db_query('SELECT FROM {users_roles} ur LEFT JOIN {role} r ON r.rid=ur.rid WHERE ur.uid=%d AND"expert"',  $data->users_uid));
  if( $role == 'expert') {
print "<div class='expert'></div>";

So if the user is an expert, print out the div of class "expert", which will display a little png that the client asked for, in the view...

Note the variable $data->users_uid which is the user who created the node. Pretty slick! Hope this helps someone...

eebanos’s picture

I have this problem:
I have created custom CCK field wich contain a numeric value, i´m trying to retrieve using views custom field a numeric value wich allows to sum all these fields values and show it using the following code:

$total = array();
$sql ="SELECT node_data_field_apto_tx.field_t_duracion_value AS times
 FROM {node}
 LEFT JOIN {content_type_registro_revision} node_data_field_apto_tx ON node.vid = node_data_field_apto_tx.vid
 LEFT JOIN {content_field_r_rev} node_data_field_r_rev ON node.vid = node_data_field_r_rev.vid
 WHERE (node.status = 1) AND (node.type in ('registro_revision')) AND ((node_data_field_apto_tx.field_apto_tx_value) = ('No'))";

$a = db_query(db_rewrite_sql($sql));
$x = array();
$i = 0;
while ($data = db_fetch_object($a))
$x[$i] = $data->times;
$total[0] += $x[$i];
return $total[0];

, the problem is when i have several values and it displays all values in a table it repeats the views custom field on each row, and i just want to display it once. Help me to solve this issue.

nkurothe’s picture

I know this is an old thread, I just started learning drupal
Thanx a ton for this, it took me three days to accomplish what I was trying for
thanx for the var_export!

agalligani’s picture

welcome #79

hockey2112’s picture

I'm not sure if this module is the solution I am looking for... I have Ubercart and the "Delivery time slots for Ubercart" module installed, and I have created a View to pull a custom report of orders. I need for that report to also include the delivery time slot chosen by the shopper on each order, but that module apparently does not have Views integration. Is there a way for me to pull the time slot value for each order into the view by using this module?

I also would like to be able to pull in each shopper's custom profile fields, as that will contain info about their allergies, etc.

I appreciate any feedback! Thanks!

ridefree’s picture

Issue summary: View changes

Been a while on this thread but I wondered if anyone had some advice for me.

I'm trying to output some specific information from one of my views.
Using print_r I can see that the field I need in this case is: node_data_field_mp3_field_mp3_data

It outputs something like this ...


All I want is the duration.

My best attempt so far is this (based on code we have working elsewhere on the site)

<div class="mp3-length">
    <strong>Length: </strong>
     <?php $mp3duration = $data->node_data_field_mp3_field_mp3_data ?>
     <?php print gmdate($mp3castduration >= 3600 ? 'g:i:s' : 'i:s', $mp3castduration) ?>

I would think that my $data->node_data_field_mp3_field_mp3_data should be something like:
$data->node_data_field_mp3_field_mp3_data['duration'] but I just can't seem to get the right syntax.

Anyone have any ideas here?
(perhaps goes without saying I'm no php expert)