0

I have created a view which displays the fields of different node types. Therefore, visually, the user will see apple fields bunched together and orange fields bunched together, and the page makes sense.

However, for each view row, a div is created for EVERY field in the view, orange or apple. For particular reasons, I need to be able to get rid of the divs which don't apply to that row.

I would imagine doing something like:

if($row->_field_data['nid']['entity']->type == '[node-type]'):

but I can't figure out which template to do this in. I tried in views-view-unformatted.tpl.php and views-view.tpl.php, and in views-view-fields.tpl.php (which are the outer wrappers) but none seemed to do it.

I thought it would be in views-view-fields.tpl.php, but when I tried inserting this into the (overriding) template

drupal_set_message("wrapper-prefix:" . $field->wrapper_prefix . " wrapper-label:" . $field->label_html . " wrapper-content:" . $field->content . "  wrapper-suffix:" . $field->wrapper_suffix);

the only thing which came back with info was $field->content

2 Answers 2

2

You should be able to accomplish this through the UI from each field settings form:

enter image description here

4
  • I'm not sure how this would solve my issue. This only adds custom css classes on the div. It wont take away a div for a unwanted field, will it? Sep 12, 2013 at 16:48
  • I'm a little confused because you seem to be using the terms div and class interchangeably. But I'm still pretty positive you can do what you want through the UI. Unchecking the "Add default classes" will remove all of the classes that views normally adds. Then you can add the specific classes you want (and you can even choose the HTML Element - it doesn't need to be a div) to each field under "Style settings". Sep 12, 2013 at 17:29
  • No, I dont want to change the class of the div/element, I want to be able to erase the div/element from that row. For example, lets say the view was of apples and trees and tree had a field leaf type which was going to be displayed. I don't want the rows displaying apple info to have a div/element of field-field-leaf-type at all. Does that make sense? Sep 12, 2013 at 18:25
  • @user1015214 Can you post the rendered markup that you want to change? Sep 13, 2013 at 18:45
0

I figured out what I needed to do. It is from the UI - I just needed to set the No Results section to hide the section, and it worked perfectly.

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.