Given these posts
---
title: Test Post A
---
---
title: Test Post B
videoEmbeds:
- "DrQZXoHlqQI"
---
This snippet from my template generates errors for posts that do not have a videoEmbeds
element defined.
Here is the error:
Failed to render pages: render of "page" failed: "<path_to>/single.html": execute of template failed: template: _default/single.html:60:32: executing "main" at <len .Params.videoEmbeds>: error calling len: reflect: call of reflect.Value.Type on zero Value
<h4 class="f4">Videos ({{ len .Params.videoEmbeds }})</h4>
Is this the only solution? (Other than defining an empty videoEmbeds
member in all my posts?
<h4 class="f4">Videos
{{if isset .Params "videoEmbeds"}}
({{ len .Params.videoEmbeds }})
{{end}}
</h4>