HUGO

Render custom html tag

Actually I have this code to render tags

{{ if .Params.tags }}
    {{ range .Params.tags }}
        <a class="bg-gray-100 rounded-full px-3 py-1 text-gray-darkest" href="{{ "/tags/" | relLangURL }}{{ . | urlize }}">{{ . }}</a>
    {{ end }}
{{ end }}

I’d like to create a custom html tag in order to centralize the rendering

{{ if .Params.tags }}
    {{ range .Params.tags }}
        <badge href="{{ "/tags/" | relLangURL }}{{ . | urlize }}">{{ . }}</badge>
    {{ end }}
{{ end }}

and the definition the badge render would be something like

<a class="bg-gray-100 rounded-full px-3 py-1 text-gray-darkest" href="{{ "/tags/" | relLangURL }}{{ . | urlize }}">{{ . }}</a>

Is there a way to do this with hugo ?

Hugo is not opinionated about HTML tags. You can output a custom <badge> HTML element.

Thanks @onedrawingperday, I was going on a wrong path. Partials seems to solve my requirements.

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