web:drupal:theme:views
Dies ist eine alte Version des Dokuments!
Inhaltsverzeichnis
Views Theming
Views Templates
Explanation taken from: https://redcrackle.com/blog/drupal-8/theme-views-templates
Views default templates are located under „/core/modules/views/templates/“ folder.
Each view uses minimum of two templates:
- The first template is „views-view.html.twig“. This template is used for all views and contains the layout for the view. (view content, header, footer, exposed form and attachments)
- The second template is the style template. The default used template will vary based on the applied view style (grid, table, html list or unformatted).
- Grid: views-view-grid.html.twig
- Table: views-view-table.html.twig
- HTML List: views-view-list.html.twig
- Unformatted: views-view-unformatted.html.twig
- The third template is „views-view-fields.html.twig“. This template is used only if the view row style is set to „Fields“. This template is responsible for looping through available fields and print fields wrappers, labels and markup.
- The fourth template is „views-view-field.html.twig“. This template is used only if the view row style is set to „Fields“. This is the last template and is responsible for printing each field markup.
Override Views Templates
Each type of the view templates above can be overridden with a variety of names. The template name is a concatenation of (base template name, view machine name, view display type and view display id - separated by 2 hyphens „–“).
The following are the possible template names sorted by precedence:
- [base template name]–[view machine name]–[view display id].html.twig
- [base template name]–[view machine name]–[view display type].html.twig
- [base template name]–[view display type].html.twig
- [base template name]–[view machine name].html.twig
- [base template name].html.twig
For example; If we want to override „views-view.html.twig“ template for our view, the following template names are valid:
- [base template name]–[view machine name].html.twig
- views-view–articles-accordion–page.html.twig
- views-view–page.html.twig
- views-view–articles-accordion.html.twig
- views-view.html.twig
- views-view-field–{views machine name}–{page or block machine name}–{field name}.html.twig
Fields
Views View Grid
- views-view-grid.css
/** * CSS for Views responsive grid style. */ .views-view-responsive-grid { --views-responsive-grid--layout-gap: 10px; /* Will be overridden by an inline style. */ --views-responsive-grid--column-count: 4; /* Will be overridden by an inline style. */ --views-responsive-grid--cell-min-width: 100px; /* Will be overridden by an inline style. */ } .views-view-responsive-grid--horizontal { /** * Calculated values. */ --views-responsive-grid--gap-count: calc(var(--views-responsive-grid--column-count) - 1); --views-responsive-grid--total-gap-width: calc(var(--views-responsive-grid--gap-count) * var(--views-responsive-grid--layout-gap)); --views-responsive-grid-item--max-width: calc((100% - var(--views-responsive-grid--total-gap-width)) / var(--views-responsive-grid--column-count)); display: grid; grid-template-columns: repeat(auto-fill, minmax(max(var(--views-responsive-grid--cell-min-width), var(--views-responsive-grid-item--max-width)), 1fr)); gap: var(--views-responsive-grid--layout-gap); } .views-view-responsive-grid--vertical { margin-bottom: calc(var(--views-responsive-grid--layout-gap) * -1); /* Offset the bottom row's padding. */ column-width: var(--views-responsive-grid--cell-min-width); column-count: var(--views-responsive-grid--column-count); column-gap: var(--views-responsive-grid--layout-gap); } .views-view-responsive-grid--vertical .views-view-responsive-grid__item > * { padding-bottom: var(--views-responsive-grid--layout-gap); page-break-inside: avoid; break-inside: avoid; }
web/drupal/theme/views.1662975436.txt.gz · Zuletzt geändert: 2022/09/12 09:37 von phoenixseo