Meta issue: #1980004: [meta] Creating Dream Markup
Issue based on: #1843754: Convert views/templates/views-view-list.tpl.php to twig

Questions:

Where are all the classes? :(

Comments:

Maybe I'm doing something wrong and all the classes are added outside twig - that's ok.
But in theming I'd like to get away from understanding what is the output that you see - a view, panel etc. The markup should explain what the content represents, but not what is it in back-end. In this case Views show list of items, so this is what should be represented in markup.

Markup proposal:

{% if wrapper_attributes -%}
  <div{{ wrapper_attributes }}>
{% endif %}
  {% if title %}
    <h3 class="item-list-title">{{ title }}</h3>
  {% endif %}

  {% if list.type == 'ul' %}
    <ul class="item-list" {{ list.attributes }}>
  {% else %}
    <ol class="item-list" {{ list.attributes }}>
  {% endif %}

    {% for id, row in rows %}
      <li{{ row_classes[id] }} class="item-list-single">{{ row }}</li>
    {% endfor %}

  {% if list.type == 'ul' %}
    </ul>
  {% else %}
    </ol>
  {% endif %}
{% if wrapper_attributes -%}
  </div>
{% endif %}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

oresh’s picture

Project: » Drupal core
Version: » 8.x-dev
Component: Twig templates conversion (front-end branch) » markup
Category: feature » task

moving to core issues.

mortendk’s picture

{% if wrapper_attributes -%}
  <div{{ wrapper_attributes }}>
{% endif %}
  {% if title %}
    <h3 class="item-list-title">{{ title }}</h3>
  {% endif %}

  {% if list.type == 'ul' %}
    <ul class="item-list" {{ list.attributes }}>
  {% else %}
    <ol class="item-list" {{ list.attributes }}>
  {% endif %}

    {% for id, row in rows %}
      <li{{ row_classes[id] }} >{{ row }}</li>
    {% endfor %}

  {% if list.type == 'ul' %}
    </ul>
  {% else %}
    </ol>
  {% endif %}
{% if wrapper_attributes -%}
  </div>
{% endif %}

no reason for the class="item-list-single", unless we begin to add classes to all our li's ... which i sure hope were not ;)

mortendk’s picture

{% if wrapper_attributes -%}
  <div{{ wrapper_attributes }}>
{% endif %}
  {% if title %}
    <h3 class="item-list-title">{{ title }}</h3>
  {% endif %}

  {% if list.type == 'ul' %}
    <ul class="item-list" {{ list.attributes }}>
  {% else %}
    <ol class="item-list" {{ list.attributes }}>
  {% endif %}

    {% for id, row in rows %}
      <li{{ row_classes[id] }} >{{ row }}</li>
    {% endfor %}

  {% if list.type == 'ul' %}
    </ul>
  {% else %}
    </ol>
  {% endif %}
{% if wrapper_attributes -%}
  </div>
{% endif %}

no reason for the class="item-list-single", unless we begin to add classes to all our li's ... which i sure hope were not ;)

jenlampton’s picture

Issue tags: +Template consolidation

Can we just use the item-list template for views list? why do we need this?

Manuel Garcia’s picture

To me using item-list would be the way to go.

Very much related: #1939062: Convert theme_item_list() to Twig

marcus7777’s picture

why have class="item-list" I think ul or ol in a wrapper div with attributes is all you need and I why not trust {{list.type}} is ul or ol
So I'd love it to be:

{% if wrapper_attributes -%}
  <div{{ wrapper_attributes }}>
{% endif %}
  {% if title %}
    <h3 class="item-list-title">{{ title }}</h3>
  {% endif %}
    <{{list.type}} {{ list.attributes }}>
    {% for id, row in rows %}
      <li{{ row_classes[id] }} >{{ row }}</li>
    {% endfor %}
    </{{list.type}}>
{% if wrapper_attributes -%}
  </div>
{% endif %}
Dragan Eror’s picture

Issue summary: View changes
FileSize
849 bytes

When I started to work on this issue the file views-view-list.tpl.php was already updated I just improved it with suggestion by marcus7777 in #1982248-6: Markup for: views/templates/views-view-list.tpl.php.

Dragan Eror’s picture

Status: Active » Needs review
FileSize
39.89 KB

Here is the screenshot of printed markup.

rteijeiro’s picture

Status: Needs review » Reviewed & tested by the community

It looks good. It's a RTBC for me ;)

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Holy cow. That's a VAST improvement in how much simpler the template file gets! Great work.

Committed and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

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