Failure to execute template

I have a summary.html for an instagram post type:

    <div class="row">
      <div class="col-12">
        {{ with .Params.featured_image }}
          <img src="{{ .Params.featured_image }}" class="img-fluid">
        {{ end }}

a sample .md looks like this:

date: 2013-02-12T09:58:42+00:00
featured_image: /instagram/2013-02-12_09.58.42_389381574568326985_297183724/2013-02-12_09.58.42_389381574568326985_297183724.jpg
title: Untitled

but hugo server fails with the following error:

ERROR 2018/02/07 19:09:09 in .Render: Failed to execute template "instagram/summary.html" for page "instagram/2013-02-12_09.58.42_389381574568326985_297183724/"

I already know, that it’s the {{ with }} part that causes issues, because if I take it out the template compiles.

What am I doing wrong?

The with narrows down the scope or context only to what gets passed to that with. So inside with if you want that whole passed argument, you just use dot… so {{ . }}.

As a side, from what I see in internal Hugo templates, it’s more conventional to have a list page param called images, and set the first element of that list as the feature image. Then fetch only the first element from that list if it exists and display that as feature.

See the use of .Params.images and index . 0 in the internal twitter_cards template in this commit.


Thank you, that was it.

I’ll still have to dive into the depths of the whole resources thing. Using Hugo for 4 weeks now :wink:

That snippet looks good, and keeping in mind that other parts like og-tags are interested in the images too makes sense… going to rewrite :smiley: