I have a HTML-list view, which generates li tags for my content. I want to add a data- attribute to each list item dependent on the content. How to achieve this?

1 Answer 1


Override style output template file using theme information in views.....

enter image description here

Override file with below code..


 * @file
 * Default simple view template to display a list of rows.
 * - $title : The title of this group of rows.  May be empty.
 * - $options['type'] will either be ul or ol.
 * @ingroup views_templates
<?php print $wrapper_prefix; ?>
  <?php if (!empty($title)) : ?>
    <h3><?php print $title; ?></h3>
  <?php endif; ?>
  <?php print $list_type_prefix; ?>
    <?php foreach ($rows as $id => $row): ?>
      <li data-attr="" class="<?php print $classes_array[$id]; ?>"><?php print $row; ?></li>
    <?php endforeach; ?>
  <?php print $list_type_suffix; ?>
<?php print $wrapper_suffix; ?>
  • 1
    Thanks for the answer, but what to do when the attribute is dependent on the content?
    – lunr
    Apr 26, 2014 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.