Post

Drupal Views

Customizing Views

Customizing views is Best done from the view admin rather then the twig files. the view admin gives you all the options to add classes and html.

view field customization

Outputing a block view

if you have generated a block with your view ensure to output it in one of the following ways

  • block layout
  • as a paragraph block

Create a Hero Banner

see sample screenshot - https://share.cleanshot.com/0rSd0qQ2

  • block type for banner
  • content type for homepage
  • view to get the fields from homepage
  • display mode to only display the required fields

https://youtu.be/sTRiJR7MiXQ?si=i6CRY6aBlNVWNJfH

  • create view
  • go to contextual filters
  • search for tax - select has taxonomy term id When the filter value is not available
  • provide a default value - Taxonomy term ID from URL.

Create a view block with fields

Create the view of content type Select the format to display fields Add specific fields to the fields section (fields need to be created for your content type) Add css class for container Set title to be none

Display content just from the current node

  • Add a contextual filter
  • Add content then ID
  • Click provide default value
  • Content id from url
  • Hit apply

as you are using the view to output content the content will also appear on the page from the fields itself on the content type. set them to disabled to hide them

views basics

views are like a custom query in wp. you can create a page out of a view or a block

examples

  • blog feed

fields

you can choose what fields are added to the view

  • fields can be reordered

formats

  • table
  • grid
  • unformatted list
  • html list

filter

  • filter criteria of the view by taxonomy
  • filters can be exposed to users on the frontend

duplicating a view

  • go to structure, content, duplicate view
This post is licensed under CC BY 4.0 by the author.