Needs work
Project:
Views (for Drupal 7)
Version:
7.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
24 Apr 2013 at 17:02 UTC
Updated:
28 Jul 2017 at 19:12 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
kris_mcl commentedThis was very useful, thanks for posting.
Based on this comment I implemented the following to get custom data- attributes on views rows. This is implemented in D7, just posting here in case it's still relevant moving forward.
I added this to template.php:
and then I customized a Views style template as indicated above, like this:
And I end up with this output:
Seems to work like a charm. Thanks again!
Edit: removed dpm(); comment in template header.
Comment #2
dawehnerIn Drupal 8 we do know use attributes all over the place. If someone manages to fix the templates without breaking existing templates/sites feel free to post it.
Comment #3
kris_mcl commentedFor anyone coming across this, I've come to realize that while this does in fact work, it only allows assigning a single name => value pair per views row. I ran into problems trying to expand the functionality to allow assigning multiple attributes to a single row. I was able to work within this limit on a recent project but I'd love to revisit this and figure out how to do it. I'll post any progress here.
Comment #3.0
kris_mcl commentedfix formatting.
Comment #4
agoradesign commentedAs the variables $attributes, $title_attributes and $content_attributes are available automatically in every tpl file (see https://api.drupal.org/api/drupal/includes%21theme.inc/function/template...), I've added these attributes, whereever it made sense to me (not every Views template has a wrapping container element, nor elements, where the title or content attributes would fit).
Comment #5
mustanggb commentedIt's a great start, but it'd also be really handy to be able to add per row attributes.
I made the following additions:
views.module
theme/views-view-table.tpl.php
Which then allows you to do something like this:
my_custom_module.module
Obviously this is only for the table format so far, it may be pertinent to include this in the theme files for other formats.
Comment #6
mustanggb commentedUpdated issue summary as dawehner confirmed this is a D7 only issue.
Comment #7
chrisgross commentedHere's a re-roll of #4 that also adds content attributes to the "view-empty" div.