Hi,

Currently all fields in a View that can have multiple values have a HTML structure like this:

<td class="view-field view-field-node-data-field-foo-field-foo-fid">
<div class="field-item">value 1</div>
<div class="field-item">value 2</div>
<div class="field-item">value 3</div>
.......
<div class="field-item">value Y</div>
</td>

Each of the assigned values are put into separate divs and these divs are assigned the class name field-item. It would be greatly beneficial if we could add an id to these "field items" so we easily customise the view using css. I would like it if the individual "field-item" divs were given classes like:

<td class="view-field view-field-node-data-field-foo-field-foo-fid">
<div class="field-item field-item-0">value 1</div>
<div class="field-item field-item-1">value 2</div>
<div class="field-item field-item-2">value 3</div>
.......
<div class="field-item field-item-x">value Y</div>
</td>

Cheers,
Stella

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

stella’s picture

Status: Needs review » Active

Sorry, some further poking around at the code shows that it's actually the cck module that this request should be posted with. The theme_content_view_multiple_field() function is the one that would need to be changed. I know that this can be overridden in the template.php, but this is a feature that I need for the lightbox2 module which I maintain. I don't believe it's possible to override a module's theme function from within another module.

Cheers,
Stella

stella’s picture

Project: Views (for Drupal 7) » Content Construction Kit (CCK)
Component: Code » Views Integration
Status: Active » Needs review
FileSize
677 bytes

I've attached a patch for the Drupal 5.x version which should do the trick.

Cheers,
Stella

stella’s picture

Status: Active » Needs review

Ping?

aliciatheduff’s picture

Category: feature » support

Nevermind!

aliciatheduff’s picture

I added the patch successfully to content_views.inc, but it doesn't seem to change the field naming at all. It still says

http://www.navanfoods.net/drupal/node/4
Here is a link to the site I am working on. The numbered field-item classes need to be applied to the "Allergen Information:" field type so I can style a unique background for each value.

Any help would be appreciated. Thank you!

stella’s picture

Category: support » feature

Strange, I applied the patch to a clean install again and it works for me. What view layout are you using?

Also, if you're pasting in code, it would be a good idea to include it in <code> tags.

Cheers,
Stella

mark.’s picture

Is there any way to accomplish this with 6.x?

Jonasvh’s picture

Version: 5.x-1.x-dev » 6.x-3.x-dev

Also searching for this

markus_petrux’s picture

Version: 6.x-3.x-dev » 6.x-2.x-dev

hmm... AFAICT, development on branch 6.x-3.x is dedicated to the new remove button, multigroup module and nested fieldgroups.

This request is not directly related to any of those features, so it needs to be worked under the 6.x-2.x branch of CCK first, and then it will be ported to the 6.x-3.x branch.

That being said, while I can help on 6.x-2.x related issues, patches here need to be approved by yched and/or KarenS.

Cheers

mason@thecodingdesigner.com’s picture

FileSize
916 bytes

I needed this for a project today and think incremental classes would be a very useful default. Here's a patch for 6.x-2.x.

markus_petrux’s picture

Title: number multiple value field items via a class name » Add incremental classes for multiple value fields in views
Status: Needs review » Fixed

I just committed to CCK2 and CCK3 an slight variation of the patches provided by stella and canaryMason (patch).

stella’s picture

w00t! thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Wolfgang Reszel’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev

How can this be done with Drupal 7?

rmathew’s picture

For Drupal 7, copy /modules/field/theme/field.tpl.php into /sites/all/themes/yourthemename/ (or /sites/all/themes/yourthemename/templates/) and change the line within the foreach to:

<div class="field-item <?php print $delta % 2 ? 'odd' : 'even'; ?> field-item-<?php print $delta; ?>" ... etc

Katy Jockelson’s picture

Issue summary: View changes

Thank you rmathew