Documentation Level: 
Introduction
Documentation Status: 
No known problems

Views basics

The Views module provides you with a powerful tool for creating customizable lists of content and more.

Using views you can pull together any information on your website and craft dynamic lists, grids, tables, reports, RSS feeds, and navigation. You can use Views to build a table of post titles, their authors, and their creation date to create a "What's New" listing; Views can pull data from fields attached to users to build a list of users and their birthdays; You can use Views to build a grid of user photos; and much more.

New installs of Views can produce displays of information related to:

  • Comments
  • Files
  • Content
  • Content revisions
  • Taxonomy terms
  • Users
  • Modules
  • Themes
  • URL redirects
  • Any fields attached to the above

 

The Views list page

The Views listing page at "Structure > Views" lists all Views available to Backdrop. A new installation of Backdrop comes with the following predefined Views:

  • Admin Content
  • Administer users
  • Front page
  • Recent comments
  • Taxonomy term

 

You will note that the last three are disabled (grayed out in the listing) and that the default item in the Operations drop button is "Enable." Disabled Views are provided by modules but have not yet been imported into the database. To use a View to display content it must first be Enabled.

The columns of the Views display table describe the View.

The first column lists "View info" and holds several pieces of information:

  • The View name
  • The displays which this View provides, such as Block, Page or Feed.
    • a view which provides a Page creates a page on the website with a URL that you can navigate to;
    • a View which has a block display creates a block that can be added to a layout in the layout UI; blocks don't have their own URL, but they can be placed in multiple locations and multiple times, just like any Backdrop block.
    • there are several other types of displays available.
  • The storage state - whether this View is
    • the default provided by a module (Default),
    • or whether it is a modified default (Overridden),
    • or whether it was created in the Views UI (Custom).
  • The type of data the View is primarily built from - nodes, or users, or comments or other entities.

The second column gives a View description; it may also list the "tag" which simply is a way to group families of Views. The third column gives the URL for any Page displays.

The final column in the Views list is the Operations dropbutton. The  options available

  • Configure - go to the Views configuration form to edit this View
  • Clone - create a clone of this View
  • Disable - disable the View
  • Delete - delete this View; this option is only available for custom Views. Module-provided Views cannot be deleted.
  • Export - redirects to the Configuration Management page where a code representation of the View is presented in a textarea field for copying.
  • Revert - only appears on overridden Views; reverts the View back to its default state.

 

Modifying default Views

The Admin content and Administer users Views provide the listings of site content and site users found on the Backdrop site at "/content" and "User Accounts" respectively. This means that it is possible to completely modify the display of the list of users by simply modifying this View! This is however not recommended. It is best to clone the View and use the clone for modifications.

 

Creating a view

The best way perhaps to understand Views is to try and create a View. You start building any view with the Views wizard. The Views wizard and the more advanced parts of Views change dynamically depending on the options you choose and exactly what you have on your site. For the purposes of this document, we will describe the steps required to create a simple list of node content.

 

Using the Views wizard

To add a new view to your website go to Admin > Structure > Views and click the Add view link. This brings up the Views wizard form.

Enter a name for the view in the View name field. To enter an additional description for the view, select the Description check box, and then describe the view in the field that appears. This description is displayed to administrators on the Views list page.

The next fieldset on the page allows you to define the content that the view displays by choosing the type of data you want your View to list and how to list it.

In the Show list, selecting an item from the list will modify the other options in this fieldset.  For example, selecting show users will cause the fieldset to reload, then only the sorted by field will remain.

 

Views wizard options

Here are some other options available to you when creating a basic view. The exact options available to you change dynamically based on what you choose and what you have on your site.

Here are some of the things you can show in your views:

  • Comments sorted by newest/oldest first
  • Content of type all/content type tagged with tag(s) sorted by oldest/newest/alphabetically
  • Content revisions sorted by newest/oldest first
  • Feed aggregator items
  • Files sorted by newest/oldest first
  • Taxonomy terms of type [taxonomy vocabulary]
  • Users sorted by newest/oldest first

 

Page and block display format options

  • Grid - A configurable table-like format
  • HTML list - An ordered or unordered list with configurable CSS options
  • Jump menu - A menu listing of links to the view items
  • Table - A dynamic, configurable table with user-sortable columns
  • Unformatted list - A simple list of the view items

 

Select what to show on views of content:

  • Teasers or full posts - with or without add comment links with or without existing comments
  • Titles - content titles only
  • Titles linked to content items
  • Fields - sets which fields (title, body, author, etc.) will be displayed

 

For this document we will stick to the default and Show content of type All tagged with no tag, sorted by Newest first.

The next two fieldsets offer the opportunity to display our content list as a page or a block; the default is to create a page, and the checkbox for this is preselected.

 

The Page fieldset

The following options are available in this fieldset:

  • Page title - will display the entered title at the top of the page and in various parts of the browser; we will use "All my content"
  • Path - allows you to set a custom path for this View; we will use "all-my-content"
  • Display format - sets the presentation and behavior of your view's page
  • Items to display - specifies the number of items your view displays on a page, with a configurable pager to navigate between them
  • Use a pager - allows site visitors to see additional view results if there are more results than can be displayed on the page (based on the Items to display field)
  • Create a menu link - adds a menu link to any navigation menu of your choice
  • Include an RSS feed - Add a feed to let visitors follow updates to your view using RSS news readers

 

The Block fieldset

To create a new block that contains the results of this view, select the Create a block check box. Configure the new block using the settings that appear:

Note: If you want site visitors to view the block, you must place it on your website in a layout. For more information, see Blocks and Layouts.

  • Block title - displays the entered title at the top of the block
  • Display format - sets the presentation and behavior of your view's block
  • Items per page - specifies the number of items per page
  • Use a pager - allows site visitors to see additional view results if there are more results than can be displayed in the block (based on the Items per page field)

 

For the purposes of this document, we will only select a page.

 

Finishing the wizard

Three options for finishing the wizard are provided:

  • Continue & Configure - redirects to the View configuration page to further modify the View settings and display options
  • Save & Exit - saves the View and loads the Views list
  • Cancel - loses all changes and loads the Views list

If Save and exit is selected, the View just created can be seen at the path "/all-my-content"

<img the view page>

 

Configuring the View

Existing Views can be edited on the View configuration page. There are two ways to access this page:

  • Find the View on the Views listing page and click “Configure view” in the Operations dropbutton
  • Hover the mouse over the actual display of the View (for example on the “/all-my-content” path for the View created above) and select “Configure View” from the contextual links menu.

 

Views terminology

It will help you dig deeper into Views if you get to know some of its terminology:

  • Displays - How your view is output: as a page, block, feed, or attachment. Every display can be individually configured and any view can have multiple displays, including multiple displays of any given display type. For example, you can build a single view that is displayed as two different blocks, a page and an RSS feed.
  • Filters - These are the basic selection criteria for what gets included in your view. Filters include characteristics like content type, publishing state, tagging, content author, commented yes or no, the number of comments, and much, much more.
  • Contextual filters - These powerful filters can do several things, including changing your view dynamically depending on where or how your view is shown on your site. For example, the same view can show one author's most commented posts on their blog page and show another author's on theirs. Contextual filters can also act as meta-filters, filtering and displaying the items in your view based on information about them (meta information) rather than just information in them, which is what normal filters do. For example, you can sort and display how many posts were published in each of the last few months, based on a contextual filter that sorts and summarizes their post dates.
  • Content versus Fields - When a display is in the "content" mode, view results can be shown in any of the standard ways they can appear on your site, such as teaser, title, or full. "Fields" are the individual pieces of information that make up the elements (including content items, users, and comments) that appear in your view. If you switch a display to the "fields" mode, you can choose which fields are shown in that display; for example the title, post date, author, and the number of comments.
  • Pager - When your view result contains more items than the limit you set for a page or block display, you can add and configure a pager to link between multiple pages or to link from a short block display to a complete page display.
  • Relationships - These add the ability to expand your view to include information from items that are not directly part of your view's results. For example, adding the relationship "Comment: user" to a content view makes all the fields relating to the authors of any comments made on that content available to your view, too.
  • Exposed filters - These allow your site visitors to customize the view they are looking themselves with one or more sort controls. For example, exposing the "Sort criteria" filter allows visitors to order view results in ascending or descending order. Almost any filter criteria can be set to be "exposed" to your site visitors.

 

The Views preview

At the bottom of the Views main configuration panel is a preview of the view content, showing that your settings work as intended. It is also possible to use the preview to change most of the settings in a view. Clicking any of the gear links will display menus to change most of the view's configuration.

TIP: If you prefer to configure your view from its preview, you can collapse the main panel by clicking the header page details just below the display buttons. (The actual link name depends on the current display.)

https://www.drupal.org/node/1578360

Sources: https://www.drupalgardens.com/documentation/views