1

I have fontmatter that looks like

---
title: "My First Post"
date: 2023-04-07T22:11:00+02:00
draft: false
slug: "hi-first-post"
tags: ['tg1','tag2']
image: "images/featured.jpg"
---

in my index.html I have

{{ range .Site.RegularPages.ByDate.Reverse }}
{{ if and (eq .Section "story") (not .Draft) (le .Date $.Date) }}
{{$image := resources.Get "images/dogs.webp" }}
            <img src="{{ ($image).RelPermalink }}" alt="Image for {{ .Title }}"></a>
{{end}}{{end}}

However, I want to reference the image: from frontmatter. The images are all stored in assets/images

I am trying to do it this way because i am trying to migrate a project to hugo. if i have to make folder for each post inside of content it will be a huge pain.

sourlemonaid
  • 504
  • 2
  • 6
  • 19

1 Answers1

1

I got it to work by using

 {{ $image := resources.GetMatch (printf "**%s" .Params.images) }}
     {{ with $image }}
     <img src="{{ ($image).RelPermalink }}" alt="Image for {{ .Title }}"></a>
     {{ end }}
sourlemonaid
  • 504
  • 2
  • 6
  • 19