Hello,

I've got one view which displays 5 fields in an "Unformatted list".

<div class="pic"><img src=""></div>
<div class="name">The Name</div>
<div class="date">The date</div>
<div class="category">The Category</div>
<div class="address">The Address</div>

how would it be possible to add a wrapper around name, date, category?

<div class="pic"><img src=""></div>
<div class="wrapper">
<div class="name">The Name</div>
<div class="date">The date</div>
<div class="category">The Category</div>
</div>
<div class="address">The Address</div>

Can I do this from within Views or do I need to update my views-view-fields.tpl.php?
And if with the views-view-fields.tpl.php - how?

<?php foreach ($fields as $id => $field): ?>
  <?php if (!empty($field->separator)): ?>
    <?php print $field->separator; ?>
  <?php endif; ?>

  <?php print $field->wrapper_prefix; ?>
    <?php print $field->label_html; ?>
    <?php print $field->content; ?>
  <?php print $field->wrapper_suffix; ?>
<?php endforeach; ?>

With an if else?

Thanks,
Transmitter

Comments

jasonzh’s picture

you can use the module:
https://drupal.org/project/views_php

drupal ,the sharp skill to eastablish website.

edrupal’s picture

My suggestion would be to do everything from within views.

In your view you would hide the Name, Date and Category fields.

If you then add a Global Custom Text field you can add these fields wrapped in the html you require. I don't know your exact field names, but the Global Custom Text field would look something like:

<div class="wrapper">
<div class="name">[name]</div>
<div class="date">[date]</div>
<div class="category">[category]</div>
</div>

Hope this helps

Ed

jasonzh’s picture

what is Global Custom Text field ?

drupal ,the sharp skill to eastablish website.

edrupal’s picture

In your view, you can add fields.

When you click 'Add' in the Fields part of the view, one of the fields that you can select is called 'Global: Custom text'.

Having selected this field, you can customise it's output as required.

Cheers, Ed

Transmitter’s picture

Very good .. That's a way to go I didn't think of. Thanks.

prakharcse’s picture

hi
you can also follow this:

first hide from display two of the three fields then in the last field you can use "rewrite behavior" and put all the wrapper element with your fields in that using replacement tokens for respective fields.

edrupal’s picture

I agree with prakharcse, their suggestion is even more concise.

Ed

Transmitter’s picture

Have to try that out - sounds good as well. Thanks :)

robhoefakker’s picture

I prefer to use the table display mode (this doesn't mean the output will be a table), and use a display template file such as:
views-view-table--"view-name"--"block-1".tpl.

<?php foreach($rows as $row):?>
<div class="pic"><img src=""></div>
<div class="wrapper">
   <div class="name"><?php print $row['name'];?></div>
   <div class="name"><?php print $row['date'];?></div>
   <div class="name"><?php print $row['category'];?></div>
</div>
<div class="address"><?php print $row['address'];?</div>
<?php endforeach; ?>