> For the complete documentation index, see [llms.txt](https://salsa-digital.gitbook.io/govcms-site-builder/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://salsa-digital.gitbook.io/govcms-site-builder/unit-6-content-listing-with-views/related-content-by-term/exercise-6-6-build-the-related-content-block.md).

# 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](/files/mh4Elb5uAkL8sylXmJeD)

## Check content tags

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

## Create the View

Follow the process outlines in [Exercise 6.5](/govcms-site-builder/unit-6-content-listing-with-views/related-content-by-term/exercise-6-5-make-a-list-of-states-territories-block.md) to create a new View Block called **Related content**.

![Image of Related content View](/files/7S4efeGRhchCWU1XFLLz)

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

![Image of Related content View](/files/nEPUeZ3N5MxiRlTtLSdd)

## 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.
4. Click **Add and configure contextual filters**.

   <img src="/files/cQAkSzJbIl75qDMXYTHe" alt="Image of Related content View" data-size="original">
5. 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**"

   <img src="/files/kQHBW3vGGTWcLYAOVzYT" alt="Image of Related content View" data-size="original">
6. Click **Apply**.
7. Click **Save** on the View page.

## 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.

   <img src="/files/65F1aTNPuXRiTYCJ6N2h" alt="Image of Related content View" data-size="original">
4. Click **Place block**.
5. 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.

   <img src="/files/d0CbVyMpdLcmvvJq53If" alt="Image of Related content View" data-size="original">
6. Click **Save block**.

## 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.

![Image of Related content menu](/files/mh4Elb5uAkL8sylXmJeD)

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**.

## 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:

![Image of Related content menu](/files/OKYqoasJbB8Y6FaBWCuc)

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.
4. Search for ID (in Category *Content*).

   <img src="/files/1S4ZmgKcj8jpCOHVXb3X" alt="Image of ID content" data-size="original">
5. Select *Provide default value* in the **When the filter value is NOT available** pane → **Content ID from URL**.

   <img src="/files/pnJNd8k1euKL14Jkemtu" alt="Image of Provide default value - Content ID from URL" data-size="original">
6. Under the **More** pane, select **Exclude**.
7. **Apply** the changes.
8. **Save** the View.
9. Test your block from the previous example. Now it should not display the current page in the block.

![Image of Related content menu](/files/dkaRmtoEU3DfYmCjxQ9L)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://salsa-digital.gitbook.io/govcms-site-builder/unit-6-content-listing-with-views/related-content-by-term/exercise-6-6-build-the-related-content-block.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
