1

I am having problems trying to control the layout and fields together in a grid style of a view.
On the internet I saw several tutorials about how to theme views, and they suggest using functions in template.php, or using view template files. I cannot find a tutorial that helps me.

Specifically, when I use a template file, I cannot control the disposition of fields (controlling the disposition of each field; controlling the fields altogether; adding conditionals; adding classes; trying to use "views-view--," "views-view-field--," "views-view-fields--," or "views-view-grid--"), and when I use a function in template.php, I cannot get the variables/values of fields.

I must say that I know how to include a custom design using the Views module interface, to control the design per fields (or controling all fields of each item, if I include the design and fields in the last field). But I want to do this using some external way to custom display in a centralized way (also to not allow to change the design from the web interface, and to have the control in a files, not in the database).

When I say a centralized way, I mean, using a file or files to control the disposition of each field, control fields together, add conditionals, add classes, add functions, (such as a theme in Drupal).

I am using Drupal 6 and Views 2.

2

in views-view-grid--viewname.tpl.php, with print_r($variables), you will find the whole values in the 'view' array (is a very huge output, so I recomend only pull 1 item in this test).

here you will discover that 'result' carry the stdClass Object with the fields of views (not it all, seems that the images are not there), to print this you can use:

print_r($variables['view']->result);

with the id of the values, you can use these values for example, show a node title:

echo $variables['view']->result[$i]->node_title;

or you can use the id of the node to get, for example, images from nodes (seems that the images are not in result).

$nIdItem = $variables['view']->result[$i]->nid;
$node = node_load($nIdItem);
echo "<img src='/".$node->field_image[0]['filepath']."'>";

so with this way is possible to control each field, set of fields, and/or add conditions, functions.

I do not know the performance or security implications of using this way, this may be a new question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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