I’m trying to loop through a set of pages and output the SVG inline from its path in the front matter, but nothing is getting returned? I’m not getting an error, just nothing being output.
Here is an example of what I have in the front matter:
logo: "/img/logo.svg"
And the code looping through pages to get these values and output:
{{ range .Pages }}
{{ $svgLogo := .Params.logo }}
{{ readFile $svgLogo | safeHTML }}
{{ end }}
The $svgLogo
variable itself will print the path to the page if I call it, it just seems like the readFile won’t read the path?
What is the full path to the logo.svg file?
Locally it’s in /static/img/
. I just tried adding static
to the beginning in the front matter and it worked! But this would fail on build I assume? Anyway around this?
No, it would not. If you are (optionally) including a different image on each page, you might consider using a page bundle. If all images have the same name you wouldn’t need front matter.
content/
├── posts/
│ ├── post-1/
│ │ ├── cover.jpg
│ │ └── index.md
│ └── post-2/
│ ├── cover.jpg
│ └── index.md
└── _index.md
{{ range site.RegularPages }}
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ with .Resources.Get "cover.jpg" }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
{{ end }}