arrow-left

All pages
gitbookPowered by GitBook
1 of 6

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Exercise 6.7: Configure data field and Event content type

For this exercise, we’ll provide hints - try to configure the event listing content type without looking back on the notes/previous instructions.

First, we’ll look at a simple view to filter out past events, then we’ll make a calendar entry using templates.

Image of Events listing

In this exercise we’re going to prepare the date settings and configure the event content type to get it ready for the next exercise.

hashtag
Review the Event content type

  1. Using experience from the earlier tutorials about content types and fields, go to the Manage Fields page of the Event content type. Review fields available in GovCMS.

  2. Move to the Manage form display page and reorder the fields in the Event content type, moving all custom fields (pattern field_[field-name]) except the Components field above the Body field. Leave the Components field below the Body.

  3. Go to Content

hashtag
Configure the date settings on your site

This once-off step is required to ensure the website date and time is set in the correct way

Note: You can also add custom data formats via the Add format button.

hashtag
Update the date field

Given events are in the future, we can’t use the date created date to list events. We need to add a date field. Follow instructions from earlier activities to create an event date field with these details:

Label
Event date

hashtag
Test and improve

  1. Test the form by creating a new event entry. Notice the date field is in the middle of the form, but would be better placed higher up.

  2. Change the order of fields, so the Event date is under the title.

hashtag
Change the URL alias

We’d like to set up the URLs so that all events are in a /events URL path, for example a URL path could be: /events/job-fair

Hint: The Event path pattern is preconfigured in GovCMS, but if you find it different to the required pattern, then follow instructions for editing URL alias patterns. Use a pattern such as: events/[node:title]

hashtag
Re-test

To test your changes, create another new event. Now, the date should appear under the event title and when you publish content it will have a unique URL following the /event path.

→
Add content
→
Event
and test the form, making further adjustments to the field position if required.
  • Check permissions - whenever you create a new content type, you always need to check the permissions. Allow Content Authors to create events. Ensure that site visitors can leave comments (the Comment module must be activated and configured).

  • Field name

    field_event_date

    Field type

    Date range

    Widget

    Date and time range

    Image of Event path pattern
    Image of Event

    Exercise 6.5: Make a list of States/Territories block

    In this exercise we’ll add a list of the States and Territories in the sidebar, so the page looks like the screenshot below.

    States Block in sidebar
    1. Go to Structure → Views. Click + Add new View. Add in these settings:

      • View name: States/Territories.

      • Select to enable Description: A list of State and Territory terms.

      • Show Taxonomy terms of type State/Territory sorted by Unsorted.

      • Select Create a block.

      • Block title: States/Territories.

      • Display format: HTML list of Fields.

      • Items per block: 0.

      • Use a pager: Leave unselected.

      • Click Save and edit.

    2. Go to Structure → Block Layout.

    3. In the Sidebar area click the Place block button.

    4. Find States/Territories block in Lists (Views) category and click the Place block button.

    5. Configure block visibility settings to only display it on the Job Posting content type.

    6. Click Save block.

    7. Scroll down and click Save Blocks to complete.

    8. Navigate to a Job posting content page and locate your block.

    Related content by term

    Site visitors would like to see content related to a specific state/territory. To do this, we need to set up an automatically generated list of States/Territories in a block with the following features:

    1. When we click on a term such as “ACT” we go to a term listing page that shows all content tagged or categorised with that term.

    2. If we then select a specific article such as “Volunteering” we see the full content page.

    3. In the sidebar of the “Volunteering” full node page we also see a “related content” block. This will pull in a list of content that’s been tagged or categorised with the same taxonomy term.

    In the following exercises we'll make a “list of terms” block and then we'll make the related content block.

    Exercise 6.8 (Challenge): Extend Content type

    If you have extra time, challenge yourself to extend this content type by making one or more of the following changes:

    • Change the content type so you can add external links to registration pages

    • Set up the content type so you can add multiple images

    • Add a related field that will show the Agency that’s sponsoring the event

    Exercise 6.6: Build the related content block

    Next we’ll add the related content block, as per the screenshot below.

    Image of Related content menu

    hashtag
    Check content tags

    Make sure you have some Job posting content tagged with the State/Territory terms.

    hashtag
    Create the View

    Follow the process outlines in to create a new View Block called Related content.

    Your view should look like the following screenshot on the edit View page. Note that the Advanced section has been expanded, as it is used in the next steps

    hashtag
    Add dynamic "contextual" filter

    The contextual filter allows us to show a list of the content with the same tags as the current content.

    1. Expand the Advanced items on the right hand side.

    2. Click Add next to Contextual filters.

    3. Search for "Has taxonomy term ID" then select the checkbox.

    hashtag
    Place the block

    1. Go to Structure → Block layout and scroll down to the “Sidebar” area.

    2. Click the Place block button.

    3. In the pop-up, filter by text “Related content” in the Lists (Views) category.

    hashtag
    Review and test

    Go to the frontend of your site and check that the Related content block has been added, as in the below screenshot.

    Check that you have some content in certain states/territories, so you can see how the block works.

    • When you click on a state (tag) on a specific article you should see a list of related content, listed by the taxonomy term. You should not see the block.

    • You should see the Related Content block when you view a Job posting.

    hashtag
    Filter out currently displayed page

    While testing the Related content block, did you notice anything unusual?

    The Related content block displays the article title of the currently displayed page:

    Let’s remove it by adding one more Contextual Filter.

    1. Return to editing the Related Content view.

    2. Expand the Advanced pane and you should see the Contextual Filter Content: Has taxonomy term ID that we created earlier.

    3. Add another contextual filter.

    Click Add and configure contextual filters.

  • Under "When the filter value is NOT available" select the "Provide a default value" option. For the Type, select "Taxonomy term ID from URL". Also check "Load default filter from term page" and "Load default filter from node page, that's good for related taxonomy blocks"

  • Click Apply.

  • Click Save on the View page.

  • Click Place block.

  • Under Visibility settings, configure block to display on all pages except the homepage. Remember to use the <front> token as the homepage identified. You may also use “/”. In addition, filter the block to only show on the Job Posting content type.

  • Click Save block.

  • Search for ID (in Category Content).

  • Select Provide default value in the When the filter value is NOT available pane → Content ID from URL.

  • Under the More pane, select Exclude.

  • Apply the changes.

  • Save the View.

  • Test your block from the previous example. Now it should not display the current page in the block.

  • Exercise 6.5
    Image of Related content View
    Image of Related content View
    Image of Related content menu
    Image of Related content menu
    Image of Related content menu
    Image of Related content View
    Image of Related content View
    Image of Related content View
    Image of Related content View
    Image of ID content
    Image of Provide default value - Content ID from URL

    Exercise 6.9: Modify an event listing for future dates

    There are a variety of ways you could list events. For this exercise, we’ll create a simple view that shows all upcoming events.

    hashtag
    Add sample content

    1. Add in 5-10 new events (either manually or using Devel generate)

    2. Make sure all events are published

    3. Include events with both past dates and future dates in the Event Date field

    hashtag
    Modify the view

    Go to Structure → Views and edit the GovCMS Events Views view.

    Customise the display

    Filter out old events