I am developing a custom theme for a specific view. I need to iterate and render each row and field, How can i do that?

Some code:

foreach($view->rows as idx => $row)
    foreach($view->field as $name => $handler)
        //I need to check if the field is hidden from
        //display here
        $view->render_field($name, idx);

I am going through with the debugger and use $handler array options, but within that I could not find any field that is visible or not.

Can anybody help?

  • "hidden from display" - you mean the option "Exclude from display" is checked for the field in the view?
    – oksana-c
    Feb 4, 2016 at 14:31
  • yes, that is the case!
    – philipp
    Feb 4, 2016 at 15:16

2 Answers 2


Data that you are looking for is located at $field->handler->options['exclude']. But it is tricky to get to.

When you mark the field as excluded, its data becomes inaccessible at the field's level in your View's template.

$row object also does not have any indication that the field was excluded via Views UI. $row contains only the value data from each field. You can confirm that by doing dsm($row); in your View template file (if you have devel module installed).

If you are overriding you View's template on the "Row style output" level, than the only object you can use to reach options['exclude'] from already excluded fields is $views.

You could do something like this at the top of your .tpl file:

foreach ($view->field as $view_field)
        //check if field is excluded
         if ($view_field->options['exclude'] == 1) {
             // field is exluded - do something
             print $view_field->field.' is excluded from this view'; // print name of excluded field 
             print $row->field_field_yourfieldname[0]['raw']['safe_value'];

so, if the field is excluded - it is going to be excluded in each row, according to that you can assign some markup or text to a variable and then print it anywhere down the template.


To iterate the each row and field, you have to override the view template. To override view template, go to the particular view.

On the right side, there is Theme field in the Advance section.

Click on the theme field, there is a various type of template to override. Click on the Row style output. A popup will open. Copy the entire code and place the code in template directory of your theme and give it a name as there are suggested and then save it.

Now you can do any kind of changes for this particular view.

  • The code above is placed there. I forgot to mention this...
    – philipp
    Oct 28, 2015 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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