Generate numbered list in a template

Can Hugo Generate a custom numbered list in a template? I want each of the five posts below to have an incremental number before them (1-5) without the decimal point (1 not 1.)

{{ range site.RegularPages | first 5 }}
<ul >
        <li>
          <a href="{{ .Permalink }}">
            <span> The list numbers go here </span>
            <h3 >{{ .Title }}</h3>
          </a>
        </li>
      </ul>
{{- end }}

go to html OL

2 Likes

I tried that before posting. But Hugo templates do not generate list numbers by default.

Yes, change the template.

You can make a copy to list5.html, change it and refer to it with layout=“list5” in frontmatter.

If it helps, I am trying to replicate the “latest business news” section on BBC’s sidebar

CSS: https://stackoverflow.com/a/5945305

The class name in the example above is “custom”. If you want to apply this to markdown:

1. Foo
1. Bar
1. Baz
{.custom}  # or {class=custom}

Requires this in site config:

[markup.goldmark.parser.attribute]
block = true  # default is false
2 Likes

I needed to apply it to the sidebar partial. But the link you shared has the solution.

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