Blog/ How To Create A View In Drupal 8

By rakesh.james Fri, 12/19/2014 - 18:24 Comments

Creating a view in Drupal 8 is similar to the process followed in Drupal 7. A major difference, however, is that Views module has been incorporated into Drupal 8’s core. It will be automatically installed during the Drupal 8 core installation. You don’t have to install any separate module (such as Views 3 or CTools).

In this article, we are going to create a simple view in Drupal for the content type “Article”

First, let's check out the Article content type by going to the following path - "admin/structure/types".

Now let’s find out the fields associated with the Article content type. This can be done by going to the following path: “admin/structure/types/manage/article/fields”.

The picture below demonstrates the path:

We can add content by going to the path “node/add/article”. The page will look like the one below:

 

After adding the content, our view will be listed in the node teaser. It looks like this:

For getting the above view, we need to follow the following steps:

  1. Navigate to Manage >> Structure [admin/structure]

2. Select the Views link to create a new view. It will take you to the Views configuration page [admin/structure/views]

 

Here, you will find a minor difference in style from the Drupal 7 Views configuration page. There are many default views. According to your requirement, you can either duplicate or edit and use these predefined views. Or you can create an entirely new one by clicking the “Add new view” button.

3. The following picture shows you how to duplicate or edit an existing view. The Duplicate feature in Drupal 8 is the same as Clone feature in Drupal 7.

4. We are going to create an entirely new view. Before that, I would like to brief you about Views and Advanced View settings.

Under “Basic”, you can configure basic settings. For example, which display should be displayed as default? Or whether you want to see the SQL queries as part of the current view.

Under “Advanced, you can access cache settings.  You can clear the views cache separately here. This is a new feature added to Drupal 8.

5. Now we are going to create our own view for listing the article content type. Go to the path “admin/structure/views/add” or “admin/structure/views” and click the button “Add new view”.

You will get a form similar to the one below. Fill in the field “View name”. In this example, I am giving the view’s name as Article list. For the fields “Show” and “of type:”, I have selected Content and Article respectively.

Click button “Save and edit”. 

It will take you to the “Article list” page. By default, it comes as master display based on our settings.

You need to change the “Show” setting to “Content”. Do this by clicking “Show: Fields” under “FORMAT”. You will get a popup box like the one below:

Select “Content” and click “Apply”. You will get another popup asking you to specify “View mode”. Select “Teaser” from the dropdown and click “Apply”.

You will now be directed to the Default Master display page. I will now add a page display for our view. Click the “+ADD” button placed after “Master” on the left. Select “Page” from the dropdown. 

The page display will automatically get added to your view.

Look closely and you will notice that the “Page” button has a red-colored border. This is an indicator of validation errors.

In this case, we need to set the Path for the page display. You can set the path under PAGE SETTINGS. Click on “Path:No path is set”. A popup will appear, allowing you to define the path to display the view.

Add the path “article/list” for our views page display. Then click “Apply”.

You will be directed back to the views page. Click “Save”.

Finally, after you have saved the view, navigate to the path you specified: article/list”. You will see that article list from our view page display. It will look like this:

Ready to get Started?