I've created a custom template for a field to display in my view. Based on the view theming information, I've named the file views-view-field--at-a-glance-test--page--field-track-icon.tpl.php (the view is called at-a-glance-test, the display is a page, and the field is field_track_icon.

The sample code given for a views-view-field template has the following comments:

* Variables available:
  * - $view: The view object
  * - $field: The field handler object that can process the input
  * - $row: The raw SQL result that can be used
  * - $output: The processed output that will normally be used.

I want to know what all is coming through in the view object, so I tried to do print_r($view). All I get is a completely blank page - there's not even a single line displayed in the rendered source. Usually this happens if there's a PHP error somewhere - am I doing something wrong? How can I print out the full contents of the view object?


I just looked at our php error log and saw this:

PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 117789481 bytes) in /home/www/expo/includes/theme.inc on line 1414

So obviously the view object is enormous... how else can I see what is coming through, since I have no control over our server's memory limits?


Per @Clive's comment below, I tried using dvm() instead of print_r, and did get some (a ridiculous amount) of output. Given that this is a template to override the display of a single field, I really want to see just the data for that particular field. So I tried dvm($field), and ended up with literally thousands of lines of nested arrays and objects. It's not pulling in just the data for this particular field, it's displaying data for the entire view, even though I passed in the field variable.

So then I tried dvm($row->field_track_icon), and got about 100 errors (Notice: Undefined property: stdClass::$field_track_icon in include() (line 28 of /home/www/expo/sites/all/themes/bluemasters/views-view-field--at-a-glance-test--page--field-track-icon.tpl.php).) The template comments state to use $data = $row->{$field->field_alias} as the format; first, what's the difference between field and field alias? I've attached a screenshot of the taxonomy term that the field I need is attached to. The field is called field_track_icon. What is the alias? Second, do I need the curly braces?

What do I need to do to get just the data for one specific field?

enter image description here

  • hi Emmy..if you are just trying to dump the objects of the view, try it instead in your local and not in prod. – ninjascorner Jun 6 '12 at 2:19
  • the number of available theme templates for views can be confusing. Try creating files for different available views theme templates and print out the variables there. you can do get_defined_vars(); to return which vars are available. As said below in the first answer, increase your memory limit. you could try setting your view to display out only 1 item. – Andrew Welch Oct 19 '14 at 17:35
  • Please have a look at the views_display class. – Ataboy Josef Nov 11 '14 at 13:18
  • Use a debugger. print_r, dvm etc that print to the screen don't have the same level of capability. Such as being able to step through and expand variable trees. drupal.org/docs/develop/development-tools/… It takes a bit of setup, but is worth it. – Interlated Oct 31 '17 at 17:15

Try to set the memory limit in your settings.php to something like this..

ini_set('memory_limit', '128M'); 

The above code will override your server php.ini settings. Take note that this may result instability of server and may attract suspension of your account.

You may need to ask your hosting support if possible.

  • We have our own (non-hosted) dev server. I don't have access to php.ini, but I do have access to settings.php, so I can try this temporarily. – EmmyS Jun 6 '12 at 4:45
  • 1
    268435456 bytes = 256M...you're decreasing the memory limit there ;) @EmmyS I think this is probably an issue to do with recursion...something in the View object contains a reference to itself, and that's causing an infinite loop (and your memory to be exhausted). Try using Devel's dvm() function instead of print_r(), you might get better results – Clive Jun 6 '12 at 8:25
  • I wasn't going to set the limit to 128M, just try the technique. But I will look at dvm, thanks. – EmmyS Jun 6 '12 at 13:48
  • @Clive - thanks! Just tried dvm and it worked. To a point, anyway - I did get an error (Fatal error: Nesting level too deep - recursive dependency? in /home/www/expo/includes/utility.inc on line 57) but that was after thousands of lines of array code, which is more than enough to give me an idea of what's coming through and how I can access individual bits of it. If you want to post that as an answer, I'll accept. – EmmyS Jun 6 '12 at 13:53
  • So one more question; I've added to the OP. This is entirely related to what dvm returns. – EmmyS Jun 6 '12 at 14:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.