Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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 %}
Comment | File | Size | Author |
---|---|---|---|
#8 | Screen Shot 2013-11-24 at 15.52.57.png | 39.89 KB | Dragan Eror |
#7 | 1982248-simplifying-markup.patch | 849 bytes | Dragan Eror |
Comments
Comment #1
oresh CreditAttribution: oresh commentedmoving to core issues.
Comment #2
mortendk CreditAttribution: mortendk commentedno reason for the class="item-list-single", unless we begin to add classes to all our li's ... which i sure hope were not ;)
Comment #3
mortendk CreditAttribution: mortendk commentedno reason for the class="item-list-single", unless we begin to add classes to all our li's ... which i sure hope were not ;)
Comment #4
jenlamptonCan we just use the item-list template for views list? why do we need this?
Comment #5
Manuel Garcia CreditAttribution: Manuel Garcia commentedTo me using item-list would be the way to go.
Very much related: #1939062: Convert theme_item_list() to Twig
Comment #6
marcus7777 CreditAttribution: marcus7777 commentedwhy have
class="item-list"
I thinkul
orol
in a wrapper div with attributes is all you need and I why not trust {{list.type}} isul
orol
So I'd love it to be:
Comment #7
Dragan Eror CreditAttribution: Dragan Eror commentedWhen 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.Comment #8
Dragan Eror CreditAttribution: Dragan Eror commentedHere is the screenshot of printed markup.
Comment #9
rteijeiro CreditAttribution: rteijeiro commentedIt looks good. It's a RTBC for me ;)
Comment #10
webchickHoly cow. That's a VAST improvement in how much simpler the template file gets! Great work.
Committed and pushed to 8.x. Thanks!