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
Comments
Comment #1
stella commentedSorry, 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
Comment #2
stella commentedI've attached a patch for the Drupal 5.x version which should do the trick.
Cheers,
Stella
Comment #3
stella commentedPing?
Comment #4
aliciatheduff commentedNevermind!
Comment #5
aliciatheduff commentedI 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!
Comment #6
stella commentedStrange, 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
Comment #7
mark. commentedIs there any way to accomplish this with 6.x?
Comment #8
Jonasvh commentedAlso searching for this
Comment #9
markus_petrux commentedhmm... 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
Comment #10
mason@thecodingdesigner.com commentedI 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.
Comment #11
markus_petrux commentedI just committed to CCK2 and CCK3 an slight variation of the patches provided by stella and canaryMason (patch).
Comment #12
stella commentedw00t! thanks!
Comment #14
Wolfgang Reszel commentedHow can this be done with Drupal 7?
Comment #15
rmathew commentedFor 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; ?>" ... etcComment #16
Katy Jockelson commentedThank you rmathew