HUGO

Mapping icons to tags

I am also looking for a solution (easier way) to do this. For menu items we’ve pre & post using which we can insert something like <i class="fas fa-pen-alt"></i>. This basically allows mapping menu items with icons. How can we do something of this sort for taxonomy terms (tags, categories) ?

content/tags/foo/_index.md

+++
title = 'Foo'
date = 2021-09-23T07:58:57-07:00
draft = false
icon_class = 'fas fa-pen-alt'
+++

template

{{ $taxonomy := "tags" }}
{{ $term := "foo" }}
{{ $icon_class := (site.GetPage (printf "%s/%s" $taxonomy $term)).Params.icon_class }}

<i class="{{ $icon_class }}"></i>

See: https://gohugo.io/content-management/taxonomies/#add-custom-metadata-to-a-taxonomy-or-term

2 Likes

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