I am trying to come up with a related content section that is an exact match of keywords given to the front matter. The indice ( keywords ) represents the title of the page that need to be shown as the related content. So here is the front matter.
{{ $related := site.RegularPages.RelatedIndices . "keywords" }}
<h3>{{ len .Params.keywords}} Related To {{ .Title }}</h3>
{{ with $related }}
{{ range . }}
Unfortunately, this returns 50 results as opposed to just 4. Could anyone chime in what could be going wrong ?
It sounds like you’re trying to use the keywords slice on one page to establish a relationship with the title field on other pages. That’s not how the Related Content feature works.
Thank you for you response. My goal could be better explained with the IMDB example.
Lets say you had a type Movies.
Movies have actors.
Movie : Avengers
Actors : [“Robert Downey Jr”,“Chris Evans”,“Mark Ruffalo”]
Please note these need to be exact matches.
When the page for Avengers is displayed, I would like to fetch the pages for associated actors and display an excerpt from those pages. See below Avengers page from IMDB
After wrangling on this for the entire day, I am still stuck. Perhaps, I shouldn’t have taken the example of the IMDB. So let me rephrase the question.
I have only one type - startups. I don’t need a taxonomy setup because there is literally one type with many to many relationships.
So for example,
A —> related to —> B,C,D
B —> related to —> C,D,E
C —> related to —> X,Y,Z
Z —> related to —> A,X,Y
These are all startups with individual pages and frontmatter.
In the frontmatter for A I define the relationship using a “related” variable.
title: A
draft: false
related: ['B', 'C', 'D']
Now using the following code I am able to fetch the related fields
{{ $related := site.RegularPages.RelatedIndices . "related" }}
{{ with $related }}
{{ range . }}
However, I would also like to fetch the related page content ( summary from ‘B’, ‘C’, ‘D’ ) , image ( image from ‘B’, ‘C’, ‘D’ ) & some other front matter stored in those startups ( variables from ‘B’, ‘C’, ‘D’ )
It seems like you’re trying to use the related slice on one page to establish a relationship with the title field on other pages. That’s not how the Related Content feature works.
With the Related Content feature, two pages are related by the indices, which in your latest example is the front matter field related. So PAGE-FOO is related to PAGE-BAR if they both have one of more of the same elements in the related slice. Think of it as an id in a database that links a record in TABLE-FOO with one or more records in TABLE-BAR.
In your case, you need to explicitly define the relationship instead of an implicit relationship based on a shared parameter. Something like this…
git clone --single-branch -b hugo-forum-topic-38363 https://github.com/jmooring/hugo-testing hugo-forum-topic-38363
cd hugo-forum-topic-38363
hugo server
Then visit http://localhost:1313/startups/startup-a/