Hugo layout calculations from param

Hi there,

I have page front matter

---
coverImage: images/plumber/1.jpg
images:
  - images/plumber/2.jpg
  - images/plumber/3.jpg
  - images/plumber/4.jpg
  - images/plumber/5.jpg
  - images/plumber/6.jpg
---

What is the less complicated method to tell Hugo in layout

{{ if }} the .Params.coverImage +images = total more than 5 then <!-- this layout -->
{{ if }} the .Params.coverImage +images = total equal 5 images then <!-- this layout -->
{{ if }} the .Params.coverImage +images = total equal 4 images then <!-- this layout -->
{{ if }} the .Params.coverImage +images = total equal 3 images then <!-- this layout -->
{{ if }} the .Params.coverImage +images = total equal 2 images then <!-- this layout -->
{{ if }} the .Params.coverImage +images = total equal 1 images then <!-- this layout -->

Thanks is advance for taking the time, I am struggling with Hugo docs a little not able to fully understand the calculations.

cheers!

{{ $imageCount := len .Params.images}}
{{ $totalCount := add $imageCount 1;
{{ if gt $totalCount 5}}
{{ do this }}
{{ else if eq $totalCount 4}}
{{ do something else
… 
etc
{{end}}

Unfortunately, add is not documented on its own currently, but only under the Math heading.
I’d probably rather go for CSS to handle that.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.