Start building sites …
hugo v0.104.1-8958b8741f552c8024af5194330fbf031544a826 windows/amd64 BuildDate=2022-09-26T17:05:45Z VendorInfo=gohugoio
Error: Error building site: failed to render pages: render of "page" failed: "C:\Users\m\Websites\Sites\websitename\themes\ThemeName\layouts\_default\single.html:10:3": execute of template failed: template: _default/single.html:10:3: executing "main" at <partial "sources.html" .>: error calling partial: "C:\Users\m\Websites\Sites\websitename\layouts\partials\sources.html:3:9": execute of template failed: template: partials/sources.html:3:9: executing "partials/sources.html" at <.>: range can't iterate over https://www.example.com/example-page/
Total in 1649 ms
git clone --single-branch -b hugo-forum-topic-41353 https://github.com/jmooring/hugo-testing hugo-forum-topic-41353
cd hugo-forum-topic-41353
hugo server
That would allow you to determine related content based on taxonomy terms or other fields in front matter; you wouldn’t have to hardcode the paths in front matter.
The you are doing it wrong. I don’t post untested code.
I’ve updated the example:
git clone --single-branch -b hugo-forum-topic-41353 https://github.com/jmooring/hugo-testing hugo-forum-topic-41353
cd hugo-forum-topic-41353
hugo server
If you need additional assistance please post a link to the public repository for your project.
Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.
If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.
git clone --single-branch -b hugo-forum-topic-41353 https://github.com/jmooring/hugo-testing hugo-forum-topic-41353
cd hugo-forum-topic-41353
hugo server
If it isn’t working for you, please post a link to the public repository for your project.
Include a link to the source code repository of your project, because we really need the context of seeing your templates and partials to be able to help you. It is trivial to do a quick git clone on your repo, then run hugo server in your project, to help you out. On the other hand, recreating your code from screenshots, or sort of guessing at it, is not.
If you can’t share your repository for whatever reason, consider creating a dummy repo that you can share, which reproduces the problem you’re experiencing.
Could it be because I’m using HTML files instead of MD files?
Front matter example:
---
title: "This is the title of the article"
description: "This is the description of the article"
category: Category
tag: Tag
type: article
related: ["/example-page-url/"]
sources: ["https://www.example.com/test-page/"]
date: 2022-11-05T10:18:00+08:00
lastmod: 2022-11-05T10:18:00+08:00
---
/layouts/default/single.html
{{ define "main" }}
<h1>{{ .Title }}</h1>
{{ .Content }}
{{ if isset .Params "category" }}<hr>
{{ partial "categories.html" . }}{{ end }}
<hr>
{{ if ne .Params.no_ads true }}{{ if eq .Type "article" }}{{ partial "bottom-ad.html" . }}{{ end }}{{ if eq .Type "video" }}{{ partial "video-bottom-ad.html" . }}{{ end }}{{ end }}
{{ if isset .Params "related" }}<hr>{{ partial "related.html" . }}{{ end }}
{{ if isset .Params "sources" }}<hr>{{ partial "sources.html" . }}{{ end }}
{{ end }}
layouts/partials/related.html
{{ with .Params.related }}
<p>Related:</p>
{{ range . }}
{{ with site.GetPage . }}
<p><a href="{{ .RelPermalink }}">{{ .Title }}</a></p>
{{ end }}
{{ end }}
{{ end }}
Only Related: (text/title above the related articles section) shows up and not a link to the related article I’ve set in the front matter.