{{ .Content }} loads for first item in list but not for the rest until small change in template

I’m having an issue where the {{ .Content }} for the first item in a list loads, but not for the other items in the list even though their other attributes load.

I have a shortcode {{< key_finding >}} that is called from within the content of another content type called chapter. For example:

Within content/chapter/Two.md:

{{< key_finding chapter="2" >}}

All of the Key Findings are stored in content/key_finding. My shortcode template calls all of the key findings within the specified chapter as follows:

<div class="container-fluid owl-carousel-wrapper">
	<div class="owl-carousel owl-theme">
		{{ range where (index .Site.Sections "key_finding") ".Page.Params.chapter" .Params.chapter }}
			{{ with .Page }}
				<div id="finding-{{ .Params.chapter }}{{ .Params.ordinal }}" data-ohash="finding-{{ .Params.chapter }}{{ .Params.ordinal }}" class="owl-carousel-item container col-md-offset-1 col-md-10">
					<h3>Key Finding {{ .Params.ordinal }}: {{ .Params.title }}</h3>
					<p>{{ .Content }}</p>
				<div class="supporting-evidence">
					<a href="{{ safeURL .Params.gcis_uri }}" class="traceable_account_a qtip-top" title="Supporting Evidence">Supporting Evidence</a>
			{{ end }}
		{{ end }}

In the carousel where they load, the variables that load for all of the Key Findings are {{ .Params.title }} and {{ .Params.ordinal }} but for some reason {{ .Content }} only loads for the first one. If I change a character anywhere in the template, or add a line break, save, and refresh, then the {{ .Content }} for each list item shows up. But when I restart hugo server, the issue happens again.

This is on my local. However we deployed the site to a stage area and it does the same thing.

Not really sure what the issue is, any help appreciated.

It looks like there is a similar, unanswered, question here:

I suspect there is a GitHub issue about this, but this is described as the “chicken and the egg problem”. A shortcode is included in a page’s content so it is impossible to to include that page’s content from that page’s shortcode, which would create an infinite loop.

Thanks for your response!

The content being called in by the shortcode is from a different file. So I have a shortcode in content/chapters/Two.md that is calling the content from a different file in content/key_finding/2_2.md, for example. The content for content/key_finding/2_1.md shows up, but not the content for 2_2.md, 2_3.md, etc. The other front matter parameters of content/key_finding/2_2.md etc. show up though ( ordinal, title ).

Yes, this is a Content thing, the front matter is metadata which is handled fine. Let just say that using .Content from shortcodes is not supported and the behaviour is undefined.

1 Like

Got it. Thanks for the info.

Fixed the issue by turning the shortcode into a partial. Then added a field in the front matter of each chapter to denote whether a chapter has key findings. Called the partial from the single.html template for the chapter.