4
votes

I have a content type that has 4 images to it.

In my View they are grouped (Group Multiple Values).

I want to put each image in a seperate li, such as:

<ul class="list">                                    
<li><img src="/images/image1.jpg"/></li>
<li><img src="/images/image2.jpg"/></li>
<li><img src="/images/image3.jpg"/></li>
<li><img src="/images/image4.jpg"/></li>
</ul>

How do I achieve this? I assume I need to theme the field template file with a foreach loop, but I can't quite figure out what I'm supposed to be doing.

Thanks :)

4

4 Answers

1
votes

The link Ran posted seems like a fine walkthrough of how to find view templates. Theming a view is not much different than theming anything else, the only tricky part is figuring out which template to override and what to call it. This information can be found in the views UI, under Theme information.

Anyways, once you get started (remember to clear cache to make Drupal use your new template), it can be hard to figure out what variables etc. you have available in order to customize the view the way you want. This gets easier over time, but a strategy I usually use, is the devel module along with dpm(). This pretty prints variables for you, and makes it a lot easier to see what/how you need to change in order to get the markup you want. Also remember to ready the comments in the views templates, it has good documentation about which variables it makes available for you.

0
votes

use views theming to do that. It will be very easy thing to do but it will require you a little bit coding (not so much).

This is a great guide to start: http://www.appnovation.com/theming-views-drupal-6-simple-way

0
votes

Guys thanks for all your help, you pushed me in the right direction.

I got round this by overriding a function called theme_content_view_multiple_field in my template.php

function MYTHEME_content_view_multiple_field($items, $field, $values) {
  $output = '';
  $i = 0;
  foreach ($items as $item) {
    if (!empty($item) || $item == '0') {
      $output .= '<li class="test field-item field-item-'. $i .'">'. $item .'</li>';
      $i++;
    }
  }
  return $output;
}

Eventually I will edit it so that it only affects this particular field (such as http://drupal.org/node/556232)

Cheers :)

0
votes

Thanks Tom! That worked like a charm for Drupal 6. Here are a few extra lines that keep the default tag (DIV) and change to LI for a specific field, where FIELDNAME is the machine name of your CCK field.

function MYTHEMENAME_content_view_multiple_field($items, $field, $values)
{
  $tag = 'div';
  if($field['field_name']=='FIELDNAME')
  {
    $tag = 'li';
  }
    $i = 0;
    foreach ($items as $item)
    {
      if(!empty($item) || $item == '0')
        {
          $output .= '<'.$tag.' class="item_'. $i .'">'. $item .'</'.$tag.'>';
          $i++;
        }
    }
    return $output;
}