Help with PageOutput Error for .Featured_Image

Hello Hugo friends!

I’m having a BLAST with Hugo! I’ve got an error (see below) I’m hoping someone can help me figure out please?

in my config.toml I’ve placed the following:


featured_image = ''"

in my partial head I’ve placed the following code:

(at line 9)

    <meta name="twitter:image" content="{{if .IsHome}}{{ $.Site.Params.featured_image }}{{else}}{{.Featured_Image}}{{end}}">

on the page legal-services/ I’ve placed the following front matter code:

title: "Bankruptcy Lawyer - Legal Services | Squiller & Hamilton, LLP"
date: 2018-09-12T20:14:18-04:00
draft: false
Description: "Need a bankruptcy lawyer? Squiller & Hamilton, LLP, located in Auburn, Indiana, provides exceptional legal services for those in need of a bankruptcy attorney."
Featured_Image: " "

When I run hugo I get the following error:

hugo Building sites . ERROR 2018/10/15 09:21:55 Error while rendering "section" in "legal-services\\": template: _default\list.html:3:8: executing "_default\\ ml" at <partial "head.html" ...>: error calling partial: template: partials/head .html:9:92: executing "partials/head.html" at <.Featured_Image>: can't evaluate field Featured_Image in type *hugolib.PageOutput

Any ideas as to what this rookie is doing wrong?

Thank you so much in advance for any help you could give me!

You are trying to access a custom front matter variable: so you need to access it as .Params.featured_image .

Note the casing:

1 Like

YOU ARE AWESOME!!! Thank you so very much! Now I found I have one small issue. The URL went into the build well but I need to cleanse / make it text I think as it took the “&” symbol in the URL and made it “&amp”

New code:

{{if .IsHome}}{{ $.Site.Params.featured_image }}{{else}}{{.Params.featured_image}}{{end}}">

I need to put an absolute URL in as I’m using a Firebase full URL.

Looking through the functions I see safeURL. Have never tried it personally but wonder if this would work

{{ if .IsHome }}
  {{ $.Site.Params.featured_image | safeURL }}
{{ else }}
  {{ .Params.featured_image | safeURL }}
{{ end }}

Tried it just now and that didn’t work but it may with another function! I’ll look into those now.

Edited the snippet to pipe to htmlUnescape first then to safeURL

{{ if .IsHome }}
{{ $.Site.Params.featured_image | htmlUnescape | safeURL }}
{{ else }}
{{ .Params.featured_image | htmlUnescape | safeURL }}
{{ end }}

Just saw the htmlUnescape function as you were typing this! I tried it already without the safeURL function and that didn’t work - I’ll now try it with the safeURL as well.

Still doesn’t work :frowning:


pipe in urlize !!!

1 Like

Pipe in function safeHTML does it !

Nice. Good to know for the future if/when I come across this

1 Like

I spoke too soon lol…

This took the dang & out lol and other parts of the URL like the ? ugg…

OK… finally got it. Just need to pipe safeHTML ! That preserves the entire link properly!

1 Like