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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 9 ■ Views<br />

Figure 9-7. Rendering tags through views<br />

As a quick demonstration of the power of taxonomy, tags, and views, click one of the tags that you<br />

entered and <strong>Drupal</strong> will render a list of all content tagged on your site with that term. Behind the scenes,<br />

<strong>Drupal</strong> is using Views to generate this list. But let’s take it one step further and allow users to filter content<br />

that is rendered from our All Articles view by entering a tag.<br />

Return to the Views administration page by clicking the Views link on the Structure page. Locate the<br />

Recent Articles view that we have been working on and click the Edit button. Click the All Articles Page<br />

display button in the Displays area of the view configuration page. Add a new filter for tags by clicking the<br />

Add button in the Filter Criteria section. Search for the Tags field by entering “tags” in the Search box at the<br />

top of the “Add filter criteria” form, and check the box for the “Content: Tags (field_tags)” field. Change the<br />

For option to “This page (override)” so that the filter is only applied to the All Articles Page display, and click<br />

the “Apply (this display)” button.<br />

The next step in the process is to select the type of interface we wish to provide, either a Dropdown<br />

list of terms to select from, or an Autocomplete field where the user types in the keyword to search for. The<br />

Dropdown field will show the user what terms are available, whereas the Autocomplete approach requires<br />

that the user know what terms they wish to search for. The option is dependent on your desired user<br />

experience. For demonstration purposes, select Dropdown, and click the “Apply and continue button.”<br />

The next step in the process is to configure the filter and how it will work. We want to allow users to<br />

select which terms to filter on, so we’ll expose the filter to the user so they can control what content is<br />

displayed by the view. To do so, check the “Expose this filter to visitors, to allow them to change it” check<br />

box, leave the “Filter type to expose” setting to “Single filter,” and change the Label to “Select one or more<br />

tags”. Leave the Operator set to “Is one of,” meaning the values that we want the user to select from are only<br />

110

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

Saved successfully!

Ooh no, something went wrong!