Establishing relationships between different types of content

I want to establish a relation between one piece of content to another using front matter attributes.

Let’s say I have the content types games and players. Each player can be associated with multiple games. On the player’s page there should be a listing of the games they play, like so:

Herp Derpson

Games I play:

I’d like to encode this relationship in the player’s front matter by referencing game slugs, for example:

- deadly-weapons
- fast-cars-5

Based on that info, the player page template should look up the referenced games to display the appropriate title and permalink for each referenced game. How do I achieve this?

I feel like I must somehow be able to achieve this using .Site.Pages, but I did not find the necessary information in the official documentation. Surely there must be an officially sanctioned way to do this.

You are looking for related content. :slight_smile:

Here’s a great article from @regis:

Hope this helps.

1 Like

I was wondering about this part:

{{ $characters := where .Site.Pages.ByTitle ".Params.novel" "intersect" (slice}}

From what I can infer about the behavior of this function call, this does not restrict the query to characters, does it?

Let’s say I have a publisher content type which also references a list of novels in its front matter. Won’t this return a combination of all characters appearing in this novel and all publishers publishing this novel?

If you read the whole article you‘ll see that it was the old way @regis used. Further down you see the new way (no intersect).

Tipp: You can ask @regis questions. He’s very responsive in his answers.

The interesting part starts here: Implementing Relationships with Related Content

That makes sense, thanks!

1 Like