Hi,

Simply put, I can't print out the fields of a view, nor can I reproduce the variables a described in the docs of view 2.

Overriding a view (cf. theming) requires one to know the variables. The docs claim one does using

<?php
  dsm(array_keys($fields));
?>

That does not print anything in my view, and yes the dev is installed, nothing is cached. I get the error:

warning: array_keys() [function.array-keys]: The first argument should be an array in /xxx/local sites/website/sites/all/themes/zen/templates/views-view--Nodes--page-3.tpl.php on line 2

However, due to this post, I found out that another command does print the variables, namely:

<?php
  $test_var = 'at least print out this string!';
  dpm(get_defined_vars());
?>

This is not what the doc states. Quite as one would expect, one can not use the following to print the actual values:
print $fields['title']->content;

Does someone know what is going on here?

Comments

merlinofchaos’s picture

Status: Active » Fixed

The docs you link are not part of the official documentation. Can't help you with that.

I can tell you that the template that you've mentioned is the outer wrapper template, and doesn't have access to the fields that way. The technique you're trying to use would be in the views-view-fields--* template, which is the wrapper around each row of the view.

You might be able to see the fields via $view->style_plugin->rendered_fields in your views-view template. but I'm not 100% sure about that.

dakke’s picture

Thanks for the reply. This indeed seem to work and prints out the various fields and the arrays.

... (Array, 2 elements)
-- 0 (Array, 7 elements)
---- field_1 (String, 8 characters )
---- field_2 (String, 7 characters )
---- field_3 (String, 6 characters )
-- 1 (Array, 7 elements)
---- field_1 (String, 12 characters )
---- field_2 (String, 16 characters )
---- field_3 (String, 21 characters )

Now I need to figure out on how to print these fields individually, and how to loop through the arrays. Probably over my head here, hints on howto or must reads more than welcome.

Thanks for the reply btw!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

typo