0

I have a relation field in netlify-cms which prints out my multiple selected related pages. Im struggling to get hugo to go through the loop and grab the title from each page using a combo of range/GetPage.

My broken Example:

{{ range .Params.chassis.availableChassis }}
{{ with .Site.GetPage "/chassis/" . }}<h1>{{ .Title }}</h1>{{ end }}
{{ end }}

Page content:

chassis:
  availableChassis:
    - Nissan
    - Renault

NetlifyCMS field setup:

- {label: "Chassis", name: chassis, widget: object, fields: [
    {label: "Available chassis", name: "availableChassis", widget: "relation", collection: "chassis", searchFields: "title", valueField: "title", required: false, multiple: true}
  ]}

If i do this i get the page title from the page, but obviously its not dynamic based on CMS choice:

{{ with .Site.GetPage "/chassis/nissan" }}<h1>{{ .Title }}</h1>{{ end }}

Possibly an easier solution ive not thought of or im not looking in the right place in the docs.

Roy Barber
  • 172
  • 4
  • 16

1 Answers1

0

Created a solution using GetPage, open to alternatives or less chunky solutions

{{ $chassis := .Params.chassis.availableChassis }}
{{ range where .Site.Pages "Type" "chassis" }}
    {{ $page := . }}
    {{ range $chassis }}
        {{ if in $page.Title . }}
            {{ with $.GetPage $page.File.Path }}
                {{ .Params.hero.heroTitle }}
            {{ end }}
        {{ end }}
    {{ end }}
{{ end }}
Roy Barber
  • 172
  • 4
  • 16