
Views for the teacher blog and assignments
Now that we have created some sample content, we are ready to complete the final step in creating the teacher blog: adding a view to display the content types in one place. As discussed in detail in Chapter 3, Getting Started, we need to complete the following three main steps to create a view:
- Add a view. We need to do the following:
- Describe the view
- Select the type of data and filters
- Select a display type
- Set display type options
- Set the display format
- Edit the view. We need to do the following:
- Add fields
- Add/edit filters
- Add/edit contextual filters (optional)
- Edit display format (optional)
- Set additional configuration options (optional)
- Define multiple display types (optional)
- Override the default values (optional)
Note
Chapter 3, Getting Started, provides a detailed overview of adding views.
In this section, we will create two views: one for the teacher blog and a second for assignments.
The teacher blog view
To get started, click on the Structure | Views link, or navigate to admin/structure/views
.
Adding a view
Click on the Add new view link to add a view. Enter the following values:
- View name:
teacher_blog
- Description:
All posts to be displayed in the teacher blog.
- The next section after Description should read: Show
Content
of typeBlog post
tagged with[blank]
sorted byNewest first
- Check the box next to Create a page
- Path:
teacher-blog
- Items to display:
10
- Check the box next to Use a pager
- Click on the Continue and edit button to continue
Editing the view
Once we have selected the view type and named the view, we can begin setting the values for the default view.
Adding fields to the view
This view will display full nodes; therefore, we don't actually need to add any fields to it. Next, we will begin adding filters.
Adding filters
For this view, we have already added two filters. The first filter selects only published nodes; the second filter selects specific content types; and the final view will select only content created by users in the teacher role.
To add this last filter, we have to add a Relationship. Relationships make other kinds of information about a node available to a view. In this case, we need to make information about the author of the node available to the view.
- Under the Advanced options, click on the add link next to the RELATIONSHIPS heading as shown in the following screenshot:
- Check the box next to Content: Author, and put Author in the Identifier box. Then, click on Apply (all displays).
- Next, we'll add the User: Roles filter.
- When configuring this filter, select Is one of under the Operator radio buttons, and teacher in the Options select box. Click on Apply (all displays) to save your choices.
- Click on the Save button to store these values.
Adding contextual filters
This view will not require any contextual filters; we can move on to setting the display format.
Setting the display format
We set the display format when creating the view, so there is no need to change anything. We do want to set a pager for this view, however. To set a pager, click on the Use pager link as shown in the following screenshot:

The difference between a Full and Mini pager is primarily cosmetic; select the option that looks best to you and click on the Apply (all displays) button. We are now ready to complete the settings for the default view.
Setting additional configuration options
For this view, we want to provide a meaningful title and some text in the header to provide some context.
As described in Chapter 3, Getting Started, add a title by clicking on the link next to the label Title. As shown in the following screenshot, titles are displayed in the browser title bar. For this example, use Teacher blog for the title:

Next, add some text for the views header by clicking on the link next to HEADER. Select Global: Text area and click on Apply (all displays). For this view, a simple header will suffice: Hello! You are viewing posts from the teacher blog. Enjoy your reading, and comment frequently.
The final option we would need to set for the view default is the Sort Criteria option. Since this was set when we created the view, we don't need to do anything else right now. Click on the Save button to save the view.
To see the teacher blog, navigate to the path you defined earlier; in this example, the path is http://yoursite.org/teacher-blog
.
Note
Remember: None of these configuration changes are permanent until you save the view. Updating the values stores the settings and you can make multiple updates as you are in the process of creating or editing the view. However, the essential final step is to save the view!
The assignment view
To get started, click on the Structure | Views link, or navigate to admin/structure/views
.
To create this view, we are going to take a shortcut: we are going to clone an existing calendar view that comes as part of the calendar module.
Cloning a view allows us to make an exact copy of it, thus saving us the time and effort of having to build the entire view from scratch.
Some modules come with default views or templates; cloning them and studying how they are put together can be a useful method of understanding more about how views work.

Click on the Add view from template link on the Views screen. You can see, in the list in the following screenshot, that there is a view template for the 'field_due_date' field in the 'node' base table option. Click on the add link next to it:

Once you have chosen to clone the view, you need to rename the cloned copy of the view and give it a new description—the first step in adding a new view. For this example, we will name the view assignment_calendar
; then, we will click on the Continue button to begin editing the view.
Editing the default values
To get the functionality we need, we need to make changes in three sections:
- Add filters in the filters section
- Add a title and header
- Edit the calendar page display
Adding filters
To add filters, click on the add icon in the FILTER CRITERIA section, as shown in the following screenshot:

We need to add one filter to this view that is Content: Type. Set Content: Type to be one of Assignment; click on the Apply (all displays) button to store your changes.
Adding a title and header
As described earlier in this chapter, and in Chapter 3, Getting Started, we can customize the title and header. For this view, the title should read Assignment Calendar. The header should give the user information about what they are seeing; for this view, a good header would be: This page shows all assignments. Get to work!
Editing the calendar display
In this section, we will edit two settings: the URL path where the view is displayed, and the menu settings.

Setting the path and menu
Both the Path and the Menu can be adjusted within the PAGE SETTINGS section.
To edit the path, click on the link next to Path. Set the new path to assignment-calendar/month. Repeat this step with the Week, Day, and Year displays, substituting the correct amount of time at the end of the URL (that is, assignment-calendar/week for the Week display). As described earlier in this chapter, and in Chapter 3, Getting Started, this means that the view will be visible at http://yoursite.org/assignment-calendar
. Click on the Apply (all displays) button to store your settings.
Then, to set the menu, click on the Parent menu item link next to Menu on the Month display. Set the menu to Normal menu item, and give it a Title of Assignment Calendar. Click on the Apply (all displays) button to store your changes.
Tip
Remember: None of these configuration changes are permanent until you save the view. Updating the values stores the settings and you can make multiple updates as you are in the process of creating or editing the view. However, the essential final step is to save the view!
To see the newly-created assignment calendar, navigate to the path we defined earlier. In this example, we set the path to http://yoursite.org/assignment-calendar
.
