Using an ordinal in a card partial isn't working

Hello,

I’m on a mission to learn how to “do” websites. I’m normally an embedded engineer. Hugo seemed interesting enough for what I wanted to do and exposed me to lots of things so I picked it. I’ve been having a great time! It feels good to use. Until I got this error:

ERROR error building site: render: [en v1.0.0 guest] failed to render pages: render of “/mnt/usb/Websites/PersonalBlog/content/_index.md” failed: “/mnt/usb/Websites/PersonalBlog/themes/artsy/layouts/baseof.html:11:19”: execute of template failed: template: _partials/gallery.html:11:19: executing “gallery” at <partial “card.html” .>: error calling partial: “/mnt/usb/Websites/PersonalBlog/themes/artsy/layouts/_partials/card.html:5:9”: execute of template failed: template: _partials/card.html:5:9: executing “_partials/card.html” at <.Ordinal>: can’t evaluate field Ordinal in type *hugolib.pageState
I’ve been googling this for a few days and I’ve tried to follow other forum posts but they don’t seem to be my issue.

Here’s the repo: GitHub - carterembedded/hugo-artsy: A galleried hugo theme for writers and media creators

Specifically the issue is in the files: partials/card.html, partials/gallery.html, {home,section}.html

in card.html I have:

{{ $type := partial "card_type" . }}
{{ $blog := .Site.Params.postTypes.Blog }}
{{ $gallery := .Site.Params.postTypes.Gallery }}

{{ $i := .Ordinal }}
<article class="
    card h-100
    {{ if modBool $i 7 }} tall {{ end }}
    {{ if modBool $i 5 }} wide {{ end }}
">

{{ if ( eq $type $blog ) }}
  {{ .Summary }}
{{ end }}

<a href="{{ .RelPermalink }}">{{ .Title }}</a>
  {{ if .Params.Image }}
     <a href="{{ .RelPermalink }}" class="thumbnail">
     <img src={{ .Params.Image }}/>
     </a>
{{ end }}

Which is called in gallery.html like this:

{{/* Here we want to define how our gallery behaves and looks */}}

{{/*  Then we use this partial in home.html and the gallery. Both will have slightly different behaviour */}}

{{ define "gallery" }}
{{ $type := partial "card_type" . }}
{{ $blog := .Site.Params.postTypes.Blog }}
{{ $gallery := .Site.Params.postTypes.Gallery }}
<div class="container">
  <div class="gallery-grid">
    {{ $entries := where .Site.RegularPages "Params.comment" $type }}
    {{ range $entries }}
      {{ partial "card.html" . }}
    {{ end }}
  <div>
</div>
{{ end }}

I am completely stuck. I just can’t progress… I’m running:

hugo v0.155.3+extended+withdeploy linux/amd64 BuildDate=unknown
GOOS="linux"
GOARCH="amd64"
GOVERSION="go1.25.6"
github.com/webmproject/libwebp="v1.6.0"
github.com/sass/libsass="3.6.6"

If I can provide anything else I will. Thank you in advance!

.Page.Ordinal isn’t a thing… what’s the objective here?

Thank you for quick reply.

The objective is to try and enumerate post cards so I can size them based on that. I’ve tried using $.Ordinal, too. I am still getting used to Hugo’s contexts.

My understanding of Ordinal is it counts instantiations of a partial on a page and based on that I want to decide the height of a post. If .Page.Ordinal isn’t a thing what am I missing? I’ve poured over the doc for it a dozen times and I just can’t see why what I’m doing isn’t working.

1 Like

No.

It is relevant to shortcodes and some render hooks.

So a shortcode isn’t the same as a partial? Okay. I will figure something else out. I’ll just pass it in externally, I guess.

Sorry for my noobness. This has been very helpful, actually.

Have a nice day!

1 Like