Hi,
Update - Solved
The following works:
{{ $teaser := string .Params.teaser_image }}
{{ .Site.GetPage "page" "photos/abandoned" $teaser }}
TDLR
How do I pass a string as an argument when it comes to using .Site.GetPage? I am using Hugo v 0.22.
For reference, the repository with all the code for the project is here.
I want to be able to fetch a page but want to pass in a string as an argument. This works sometimes and has very unpredictable results.
This is what I am doing inside my single.html template for the album content type.
{{ $teaser := .Params.teaser_image }}
{{ .Site.GetPage "page" "photos/abandoned" $teaser }}
This works but it raises the following error:
Error while rendering "page": template: albums/single.html:15:46: executing "albums/single.html" at <$teaser>: invalid value; expected string
If I try the following:
{{ $teaser := .Params.teaser_image }}
{{ .Site.GetPage "page" "photos/abandoned" "$teaser" }}
I get <nil> output as a result.
I don’t understand why this error is popping up. From my understanding, the $teaser variable is a string.
If I do the following, then things work as expected and no error message appears.
{{ .Site.GetPage "page" "photos/abandoned" "cite-foche-reflections.md" }}
For reference, the content file for the album I am rendering is as follows:
---
date: 2017-05-31T13:45:38Z
description: "Abandoned"
identifier: "abandoned"
title: "Abandoned"
weight: "9"
teaser_image: "cite-foche-reflections.md"
---
# Abandoned
This is the content for Abandoned
The template file layouts/albums/single.html looks like this:
<!DOCTYPE html>
<html lang="{{ .Site.LanguageCode }}">
<head>
{{ partial "head" . }}
</head>
<body>
{{ partial "header" . }}
{{ partial "nav" . }}
<main class="page albums" role="main">
{{ $teaser := .Params.teaser_image }}
{{ .Site.GetPage "page" "photos/abandoned" $teaser }}
<section class="teaser">
<!-- <img data-src="https://res.cloudinary.com/matt-finucane-portfolio/image/upload/w_2560/v1497000103/abandoned/cite-foche-reflections.jpg"> -->
</section>
<section class="content">
{{ .Content }}
</section>
</main>
{{ partial "footer" . }}
{{ partial "scripts" }}
</body>
</html>
Is what I am trying to achieve possible in Hugo, or am I going down a rabbit hole?
Thanks,
Matt