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 10 ■ Creating Pages<br />

The first view display that we will create is the teaser list of the latest five articles. Click the Add button<br />

to create a new display, and select Block from the list of options. Click the Block link in the “Display name”<br />

field and change the “Display name” to “Latest Articles.” Click the None link next to the Title field and enter<br />

“Latest Articles” as the title to display at the top of the view’s output. Next, for the Show settings, change what<br />

to show from Fields to Content and select Teaser from the list of formats to display. Click the “Use pager” link<br />

and change it to “Display a specified number of items” and set the number of items to display to 5. Finally,<br />

click the Save button.<br />

The second view display that we will create is a Featured Article block. We’ll randomly select an article and<br />

display the full article on the page. To create this view display, click the Add button and select Block. Change<br />

the “Display name” to “Featured article” and the Title to “Featured Article.” Make sure you select “This block<br />

(override)” in the For select list at the top of each element you change; otherwise your changes will apply to all<br />

the view displays. Change the Show settings to Teaser to display the shortened version of the article. Next, click<br />

the Add button in the Sort Criteria section and add a new sort order. Select Global from the Type drop down<br />

list and from the list of values available for Global, select Random and click Add and configure sort criteria.<br />

Leave the Export this sort to visitors checkbox unchecked and complete the addition of the new sort criteria by<br />

clicking the Apply button. Next, delete the “Post date (desc)” sort criteria by clicking the drop-down arrow next<br />

to the Add link (displayed to the right of Sort Criteria) and selecting Rearrange. On the “Rearrange sort” page,<br />

click the Remove link associated with “Content: Post date (desc)” and click the Apply button. Next, change the<br />

number of items to display in the Pager section from 5 items to 1. Finally, click the Save button.<br />

We’ll assign the two blocks that we’ve just created to the “What to do Around Los Angeles” page to<br />

demonstrate the fruits of our labor. Click the Structure link and select the “Block layout” link. In the right<br />

column you will see the list of available blocks to place. In the section titled Lists (Views), you will see the<br />

two blocks that we just created. Click the Article: Featured Article link and assign it to the “Sidebar second”<br />

region. Click the Show Pages vertical tab and click the “Show for the listed pages” radio button. In the text<br />

area enter the URL to the page. In my case the URL to my article about what to do around Los Angeles can<br />

be found at /node/7, so that is the value that I will use to restrict this block to only that page. Click the Save<br />

button. Do the same steps for Article: Latest Articles, but in this case select the Content region. Finally, click<br />

the “Save blocks” button at the bottom of the “Block layout” page. Next visit the “What to do Around Los<br />

Angeles” page to see the progress of our page-building efforts (see Figure 10-5).<br />

Figure 10-5. Page build progress<br />

122

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

Saved successfully!

Ooh no, something went wrong!