arrow-left

All pages
gitbookPowered by GitBook
1 of 3

Loading...

Loading...

Loading...

Views - Part 2

hashtag
Views displays – multiple views in one

Views allows you to reuse existing configuration - in a good way. If you create a page listing of your content and need to provide a block of page titles or add an RSS feed (even create more pages) – View Displays can be used rather than duplicating views.

Image of Page Display and Block content views displays

If you explore the existing GovCMS Block Article View – three Displays exist: Page, Feed and Block. Go to Structure → Views → GovCMS Block Article Views.

Views displays allows you to easily create a duplicate of any other display and add some customisations and overrides.

hashtag
Views caching

Views also allow you to speed up your site if you have two views that load similar fields. This is because with Views you can cache both the query and rendered output, which reduces the load on your database. You can learn more about Views caching in Unit 10.

hashtag
Views attachments

The Views module includes some pre-built templates, which can be activated and edited to suit your requirements. Click on the links in the Format section to review these (see screenshot above).

hashtag
The Views editing interface – Format pane

In this section we’re going to look at the Views editing interface.

  • A. Displays: Create multiple displays from the same view. This might mean multiple pages with different filters or blocks, RSS feeds, etc.

  • B. Format: Output content into lists, tables, or show the full content (node) display.

  • C. Fields: Specify fields such as title, date, taxonomy, etc.

hashtag
Related content with Views (contextual filters)

In the Unit 6 exercises, we used filters in Views to limit the data displayed (e.g. to show certain content types or show content categorised with a specific taxonomy term. For our Jobs website, we want to show related content when we view a job listing for a specific state/territory, without having to build a new view for each new state. The solution is to use context to control the items displayed. We can set up GovCMS to check the taxonomy terms from the article, and dynamically include content that’s categorised with the same term.

We can configure a view so that it’s filtered dynamically, depending on the context. For example, we could use a contextual filter to add a block that contains related content or that presents a list of articles by the same author.

Exercise 6.4: Reuse a Views template

Duplicate a previously created View and modify its filters to display a full blog article content item and five more most recent blog article titles below it. Use the same techniques as in the previous exercise.

D. Filter criteria: This is the most important aspect, since you limit the selection this way.

  • E. Sort criteria: Specify ordering of the list - by created date, by title or any other property.

  • F. Header: Add arbitrary HTML to the top and bottom of your views.

  • G. Pager: Specify how many items to display or whether or not to show a "previous/next" pager.

  • Image of GovCMS Block Article View
    Image of Views pre-built templates
    Image of Views pre-built templates
    Image of Views editing interface

    Exercise 6.3: A customised News and Media page

    In this exercise we’ll customise the Employment news View page we created earlier, making it show three items of recent content, then a bulleted list of titles of seven more jobs. Below is what the layout of the page will look like.

    Showing 3 jobs, the more jobs

    There are seven stages in this process:

    1. Locate the View

    2. Change the number of items to display

    3. Add a new display: an attached list

    4. Add a header to the attachment

    5. Change the offset to exclude the first three articles

    6. Change the attachment setting

    7. Review your changes

    hashtag
    1. Locate the View

    1. Navigate to the admin/structure/views and edit the Employment news view.

    hashtag
    2. Change the number of items to display

    1. Under Pager click "mini" to change the settings.

    2. Select "Display a specified number of items".

    3. Click Apply.

    Now check your preview to confirm three items are displayed. Scroll down to the Preview section to check only three items are displayed.

    hashtag
    3. Add a new display: an attached list

    Next we'll add a list of seven more recent jobs to the bottom of this view.

    1. At the top, click the +Add button and select "Attachment".

    2. You’ll now have more than one display available, with the one you’re editing highlighted. Make sure the correct one is always highlighted when you’re editing views.

    3. Next click Unformatted list under Format in the left column. A new window will pop up, giving you the option to select the display you're changing.

    hashtag
    4.Add a header to the attachment

    1. Under the Header section on the View page click Add.

    2. Make sure you’re editing "This attachment (override)".

    3. Search for and select "Text area". Apply changes.

    hashtag
    5. Change the offset to exclude the first three Jobs

    Our Attachment view will be displayed below the first three Jobs, so we need to exclude those from our list to avoid displaying duplicate content:

    1. Make sure you're still editing the Attachment display. Under the Pager settings in the centre column, click "10 items" to change the setting.

    2. Change the “Items to display” to 7 and the "Offset" to 3. Apply the changes.

    hashtag
    6. Change the attachment settings

    1. Under "Attachment settings" in the centre column click the option: "Attach to:" Not defined.

    2. Select "Page". Apply the changes.

    hashtag
    7. Review your changes

    1. Click the Save button to save your changes.

    2. Return to the Employment news page and review the changes.

    3. You may create more Jobs content to test it. Make sure you publish any new content before reviewing the Employment news page.

    Change Items per page: 3.
  • Click Apply.

  • Select "This attachment".

  • Select "HTML list".

  • Click the Apply (this display) button.

  • The next screen is “Attachment: Style options”. Leave all settings as default and click the Apply button.

  • Under Format → Show, click Content to change the settings. Select the Fields radio button.

  • Then click Apply on the final screen, leaving the settings as they are.

  • You'll see that Views added a Title field for us. If we needed more fields to be displayed, we could have added them using the Add button. Let’s continue with only the Title field for now.

  • Check the Preview pane at the bottom of the page to confirm our display is correct.

  • Make sure the Text format for the Content field is Rich Text. Then type in the Content field: <p>More Jobs</p>

  • Apply the changes.

  • Check that the preview shows text ‘More Jobs’ above the list.

  • Click "Attachment position:Before".
  • Select "After". Apply the changes.

  • Showing the edit button in the Views listing page
    Showing preview results
    Highlighting the Attachment display tab
    Pager options settings
    Attach to "not defined" link
    Select Page
    Image of Position: After
    Field settings
    Attachment style settings
    Attachment row style settings
    Title field in View
    Adding content to global text area
    Preview of new header
    Final Views page