Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Drupal 8 Theming with Twig

You're reading from   Drupal 8 Theming with Twig Master Drupal 8's new Twig templating engine to create fun and fast websites with simple steps to help you move from concept to completion

Arrow left icon
Product type Paperback
Published in Mar 2016
Publisher Packt
ISBN-13 9781782168737
Length 376 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Chaz Chumley Chaz Chumley
Author Profile Icon Chaz Chumley
Chaz Chumley
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Setting Up Our Development Environment 2. Theme Administration FREE CHAPTER 3. Dissecting a Theme 4. Getting Started – Creating Themes 5. Prepping Our Project 6. Theming Our Homepage 7. Theming Our Interior Page 8. Theming Our Blog Listing Page 9. Theming Our Blog Detail Page 10. Theming Our Contact Page 11. Theming Our Search Results 12. Tips, Tricks, and Where to Go from Here Index

Drupal Views and Twig templates


Unlike most of Drupal's templates, Views do not provide a file name suggestion for overriding Twig templates. So how do we know exactly what to name our template? View templates can be created in a variety of ways, but the easiest way to remember this is by following this rule:

[base template name]--[view machine name].html.twig

So in the case of our Categories view, will want to create a new Twig template with the name views-view-unformatted--categories.html.twig.

Begin by navigating to the core/modules/view/templates folder and following these remaining steps:

  1. Copy views-view-unformatted.html.twig and place it into our theme/octo/templates folder.

  2. Rename views-view-unformatted.html.twig to views-view-unformatted--categories.html.twig.

  3. Next, we will need to replace the current markup with the following new markup to convert the default <div> to <ul>:

    New markup

    {% if title %}
        <h3>{{ title }}</h3>
    {% endif %}
    
    <ul class="nav nav-list...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime