3

I have been working with a View and I noticed an inconsistency in the way fields are output (unformatted list).

Most of the fields appear below their labels, but one (Post date) appears on the same line.

I looked at the source and I saw that the date was wrapped in a span and the other fields were wrapped in a div:

<div class="views-field views-field-field-last-name">
    <span class="views-label views-label-field-last-name">Last Name: </span>
    <div class="field-content">Thacker</div>  
</div>  
<div class="views-field views-field-created">
    <span class="views-label views-label-created">Post date: </span>
    <span class="field-content">Wednesday, April 9, 2014 - 14:39</span>
</div> 

Why is this happening? Is it important for this to happen? How can I change this so that everything is wrapped in a div?

3 Answers 3

3

If you click on a field in your view, you get the 'Configure Field' dialog. Look for "Style settings", because there you can customize the Field HTML, Label HTML and the wrapper. E.g. with 'Label HTML' option you can change the <span> to a <div>.

1

While the accepted answer shows you how to customize the field HTML, the answer might be simpler and might all be based on whether you are choosing to format fields in a view as an inline field or not. For example, your example shows this:

<div class="views-field views-field-field-last-name">
    <span class="views-label views-label-field-last-name">Last Name: </span>
    <div class="field-content">Thacker</div>  
</div>  
<div class="views-field views-field-created">
    <span class="views-label views-label-created">Post date: </span>
    <span class="field-content">Wednesday, April 9, 2014 - 14:39</span>
</div> 

My guess is that if you were to open up that view to edit it, and click “Settings” under “Format -> Show -> Settings” you will see a list of your selected fields in that view under the heading “Inline fields” with checkboxes new to them like this; using the standard @font-your-face view as an example:

The default '@font-your-face' view as seen in Drupal 7.

Any field you would set as an inline field by checking off those checkboxes would make the field render in a <span> element since that is an HTML inline element; unchecked the defaults to a <div> element which is a block-level element.

0

You can select the field and label html in views. By clicking on your field below popup will open. In this you can select the default field/label html or anything like label or span you want to use in display.

enter image description here

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.