- Drupal for Education and E/Learning
- Bill Fitzgerald
- 1920字
- 2021-05-28 17:43:25
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, we need to complete three main steps to create a view.
- Add a view
- Set the defaults
- Add fields to the view
- Add filters
- Add arguments
- Set style
- Set additional configuration options
- Add a display type
Note
Chapter 3 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 the Administer | Site Building | Views link, or navigate to admin/build/views
.
Click the Add tab to add a view.
Enter the following values:
- View name: teacher_blog
- View description: All posts to be displayed in the teacher blog.
- View tag: teacher
- View type: Node
Click the Next button to continue.
Once we have selected the View type and named the view, we can begin setting the values for the default view.
This view will display full nodes; therefore, we don't actually need to add any fields to it. For testing purposes, we will add one field, the Node: Title field. Adding this field can be useful if we ever need to troubleshoot a view.
Once we have added the Node:Title field, we will begin adding Filters.
For this view, we will add three filters. The first filter will select only published nodes; the second filter will select specific content types; and the final view will select only content created by users in the teacher role.
To add these filters, we select Node: Published or admin; Node: Type, and User: Roles
When configuring these filters, set the following values:
Node: Type: Is one of Bookmark and Blog post
User: Roles: Is one of teacher
Node: Published or admin does not have any configuration options.
Click the Update button to store these values.
For the style settings, we will set the Row style. The default value is set to display Fields, and we want to display the full post.

To set the Row style, click the Fields link shown in the preceding screenshot by Item 1. Then, select Node as shown in by Item 2.
Click the Update button; this brings up the configuration options pictured in the following screenshot:

Deselect both options, as shown in the preceding screenshot, and click the Update button.
As pictured in the following screenshot, you can see your options take effect in the Live preview pane. In this example, the Live preview has switched from showing the list of titles to showing the full posts.

Now that we have adjusted the style to show full nodes, we also want to set a pager for this view. To set a pager, click the Use pager link as shown in the following screenshot:

The difference between a Full and Mini pager are primarily cosmetic; select the option that looks best to you, and click the Update button. We are now ready to complete the settings for the default view.
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, add a title by clicking the link next to Title in the Basic settings section. 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 in the Basic settings section. 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 need to set for the view default is the Sort Criteria. For this example, we will select the Node: Post date option, and set it to sort Descending. This will sort the posts in reverse-chronological order, with the most recent posts appearing at the top of the view.
Click the Update button to save the Sort Criteria, and then click the Save button to save the view. Next, we will add a display type.
For this view, we will add a Page display. As described in Chapter 3, select Page from the display options drop-down menu, and click the Add display button.

Once you have added the Page display, shown by Item 1 in the preceding screenshot you will be presented with an information message in the Live preview pane shown by Item 2.
As stated in the information message, we need to define a path for the page; we do this in the Page settings.
To define a path, click the None link next to Path in the Page settings. Define the path as teacher-blog
, and then click the Update button to store the changes.
Finally, we will add a menu item by clicking on the No menu link as pictured in the preceding screenshot by Item 3. Define the menu as a Normal menu entry, and title the menu as Teacher blog.
Click the Update button to save your changes, and then click the Save button to save the view.
To see the Teacher blog, navigate to the path you defined above; in this example, the path is http://yoursite.org/teacher-blog.
The Assignment View
To get started, click the Administer | Site building | Views link, or navigate to admin/build/views
.
To create this view, we are going to take a shortcut: we are going to clone the 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.
Before we can clone the calendar view, we need to enable it by clicking the Enable link as shown in the following screenshot:

Once the view has been enabled, we can clone it by clicking the Clone link as shown in the following screnshot:

Once you have chosen to clone the view, you need to rename the cloned copy of view, and give it a new description—the first step of adding a new view. For this example, we will name the view assignment_calendar; we will change the View description to A calendar view of assignments; and we will give it a View tag of calendar, assignments. Then, we will click the Next button to begin editing the view.
To get the functionality we need, we need to make changes in three sections:
- Adjust the date field in the Fields section
- Add filters in the Filters section
- Adjust the date argument in the Arguments section
Additionally, we will edit the Title and the Header in the Basic settings section; these two additional values to make the view more descriptive and informative for the end user.
The default calendar view that we cloned looks at the date on which a piece of content was created. We, on the other hand, are creating an assignment calendar, so we care about when the assignment is due. To reflect this, we need to switch the posted date to the due date.
First, we need to add in the due date field from the Assignment content type. To do this, click the link to add fields as shown in the following screenshot by Item 1:

To find the Due date field we created earlier in this chapter, select the Content filter as shown by Item 2.
Then, select the Content: Datetime: Due date (field_due_date) option. Click the Add button to add the field to the view.
Format the display to show a Short date, and click the Update button to store your changes.
Then, click the rearrange icon as shown in the following screenshot by Item 1:

Then, remove the Node: Updated date field by clicking the remove icon as marked by Item 2. Click Update to store your changes.
To add filters, click the Add icon in the Filters section, as shown in the following screenshot:

We need to add two filters to this view: Node: Published or admin and Node: Type.
Set Node: Type to be one of Assignment; click the Update button to store your changes.
To edit the existing argument, click the link in the Argument section as shown in the following screenshot:

This specific date argument brings up the configuration settings as seen in the following screenshot. Fortunately, we only need to adjust one minor setting on this screen.

As shown in the preceding screenshot, we need to select the Content: Datetime: Due date (field_due_date) option in the Date field(s) section.
Then, click the Update button to store the settings.
As described earlier in this chapter, and in Chapter 3, we can customize the Title and Header in the Basic settings section. 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!
To edit the Calendar Page display, click on the Calendar page option. In this section, we will edit two settings: the URL path where the view is displayed, and the menu settings.

Both the Path and the Menu can be adjusted within the Page settings section.

To edit the path, click the link next to Path. Set the new path to assignment-calendar. As described earlier in this chapter, and in Chapter 3, this means that the view will be visible at http://yoursite.org/assignment-calendar.
Click the Update button so store your settings.
Then, to set the menu, click the link next to Menu. Set the menu to Normal menu item, and give it a Title of Assignment Calendar.
Click the Update button to store your settings.
Then, click the Save button to save your view.
To see the newly-created assignment calendar, navigate to the path we defined above. In this example, we set the path to http://yoursite.org/assignment-calendar.

- AutoCAD 2010中文版基礎教程(第2版)
- Excel圖表與表格實戰技巧精粹
- Hadoop核心技術
- 虛擬現實:開啟現實與夢想之門
- ABAQUS基礎入門與案例精通
- AI繪畫:Stable Diffusion從入門到精通
- 中文版Rhino 5.0完全自學教程(第3版)
- Adobe創意大學Illustrator CS5 產品專家認證標準教材
- 綁定的藝術:Maya高級角色骨骼綁定技法(第2版)
- UG NX 8.0模具設計教程
- Autodesk Ecotect Analysis綠色建筑分析應用
- 音樂日記:Studio One 6場景×風格編曲實用教程
- UG NX 12.0中文版從入門到精通
- LaTeX入門與實戰應用
- MATLAB R2024a完全自學一本通