I'd like to take advantage of Drupal's default CSS for even/odd rows in a table.
I use Views to list the content of a custom entity with 'Table' format.
I don't know where to put this setting...

Thanks in advance

P.-S. I use Drupal 8 (8.1.2)


This can be related to Drupal, since you want to add classes to table rows, here is how you do it:

Copy the core/themes/classy/themplates/views/views-view-table.html.twig to your theme's template folder, and change the following lines (line 95):

    {% for row in rows %}
      {% set parity = cycle(['odd', 'even'], loop.index0) %}
      <tr {{ row.attributes.addClass(parity) }}>
  • Works fine! Thanks. Would like now to add my own CSS file to replace Drupal's default behavior. But I can't make it work! Tried to add {{ attach_library('amap/myLibrary') }} to 'amap_distributions_dates.html.twig' that is in 'templates' folder of my module. – gbmapo Jun 9 '16 at 21:25
  • I think maybe you should open another issue, but before that: 1. Your code seems to be alright. Be sure that you have an "amap" module, where you have a amap.libraries.yml and you have a "myLibrary" root yaml key there. 2. Also clear cache, or turn off twig cache. Try to check, if you css is loaded or not. – ssibal Jun 10 '16 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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