18.11.2015 Views

Beginning Drupal 8

Todd Tomlinson - Beginning Drupal 8 (The Expert's Voice in Drupal) - 2015

Todd Tomlinson - Beginning Drupal 8 (The Expert's Voice in Drupal) - 2015

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9 ■ Views<br />

Figure 9-1. Verifying that Views is installed and enabled<br />

The Views module is the behind-the-scenes component that handles the extraction and display of<br />

content from the database. The Views UI module, where UI stands for User Interface, is the administrator’s<br />

interface for creating and configuring views. We’ll spend the majority of the rest of this chapter in Views UI.<br />

Creating Your First View<br />

With Views installed and enabled, we’re ready to proceed. But a view without content is, well, just a blank<br />

page, so the first step is to create some content. We’ve created several articles prior to this chapter, so let’s<br />

use those as the basis for our first foray into views. If you skipped the previous exercises or have deleted the<br />

articles that you created, then take a moment to create several.<br />

We are now ready to create a view that will display a list of articles. Click the Manage link at the top of<br />

the page, the Structure link in the secondary menu, and then the Views link, which brings you to the Views<br />

administration page. You’ll notice that there are already several views listed on this page. These are views<br />

that are part of <strong>Drupal</strong> core and provide lists of items such as recent content, recent comments, who’s new,<br />

who’s online, and others. You’ll recognize the output of some of these views if you stepped through<br />

Chapter 8, as these are the views that generate the output that is displayed in several of the blocks that we<br />

used in that chapter.<br />

To add a View, click the “Add new view” button at the top of the page, which reveals the page for<br />

creating a new view (see Figure 9-2). On this page, define the following:<br />

• View name: The name must be unique (a name that has not been used for another<br />

view on your site). It’s a good idea to pick a descriptive name that conveys the<br />

purpose of the view so that others looking at the list can easily identify the right one<br />

to use. For the first view, use Recent Articles as the name.<br />

• Description: This is another field that you can use to provide additional information<br />

about the view. Check the box next to Description and enter “A list of recent articles<br />

published on the site.”<br />

• View Settings: This group of fields defines what type of content is going to be<br />

rendered by the view. If you click the Show list, you’ll see various options such as<br />

Content, Log Entries, Files, Comments, Content Revisions, Taxonomy Terms, and<br />

Users. The focus of our view is on Article content, so select Content. In the “of type”<br />

field, select Article, the name of our content type. The “tagged with” field provides<br />

the ability to limit the results of our view to only articles that contain those terms.<br />

We’ll skip the “tagged with” field and move to the “sorted by” option. Choose<br />

Unsorted (I’ll cover sorting later in this example).<br />

100

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!