Hi, is there anyway to configure it such that the taxonomy page titles don’t have the tag titlecased?
For example, if the tag is python
, at /tags/python
, the title is Python
instead of python
. Is there a way to turn off this behaviour?
Hi, is there anyway to configure it such that the taxonomy page titles don’t have the tag titlecased?
For example, if the tag is python
, at /tags/python
, the title is Python
instead of python
. Is there a way to turn off this behaviour?
You can choose to use .Section
or .Type
instead of .Title
.
… or {{ .Title | lower }}
.
That doesn’t work. You get tags
instead of python
at /tags/python
.
That would lower all the titles of list pages, which is not what I want. I have other list pages that are not taxonomy pages. Also I wouldn’t want the tag lowered if it was originally capitalized–I just want the tags in taxonomy pages to be presented as what they actually are.
In your list.html
it is possible to wrap what @kaushalmodi said in the following condition
{{ if in (.Permalink | string) "tags" }}
...
{{ end }}
See this Github issue to get an idea of what this code block does.
Yeah, except I don’t want the tag names to be lowercase if they were originally capitalised, I just want them as they were typed. Is there no way to just turn off the capitalization behaviour?
I find it weird that it is the default behaviour because if we wanted that then we would just do something along the lines of title .Title
instead of trying to work around this.
One way would be to output the taxonomy keys like so:
<ul> {{ range $key, $value := .Params.tags }} <li> {{ $value }} </li> {{ end }} </ul>
Another option would be to set everything to lowercase using css.
Of course, you are correct. I misunderstood.
It can or cannot lower the title of all “list” pages… it depends where you put that code. If you put this in layouts/_default/tag.terms.html
layouts/_default/taxonomy.html
, it will lower case only the taxonomy term titles, like python
in your example.
In there, you can even put conditions for tag terms for which you would want to skip lower-casing.
A finer grained control would be to manually specify the titles for each tag term in their respective branch bundle (e.g. content/tags/python/_index.md
) using the title
front-matter. But that would be a serious overkill… it would be difficult to keep on maintaining an _index.md
for each new tag term.
@kaushalmodi @brunoamaral Please see what I said previously:
Bottom line is: I don’t want to do a blanket lowercasing to all the tags.
Thanks for this, I tried to put this on list pages but it doesn’t seem to return anything…it seems .Params.tags
is empty?
You are right, it is definitely overkill, especially when I have no special characters or anything in my tags, and not even requesting any changes at all to be made to them.
Go templates are hard because everything renders based on the context.
.Params.tags
is empty on a list page because it is populated by a Section’s _index.md
Therefore to render the tags of your Pages in a list you need to use range
Something like:
<ul>
{{ range .Pages }}
{{ range $key, $value := .Params.tags }}
<li> {{ $value }} </li>
{{ end }}
{{ end }}
</ul>
And lo and behold now you will have your tags as you typed them originally.
P.S. It’s trivial to render the link to the corresponding taxonomy term, but I’m not going to cover that here, see the Docs and search the Forum.
Please read my question carefully. I am not asking for a list of tags of a post, those render fine.
Instead, I’m on tag page, the title being the tag (for example python
) and the list items are the posts with that tag.
Ah I found the solution, I think. Using .Data.Term
instead of .Title
for tag pages seems to solve the problem.
Ah yes, I use it myself (note the lowercase hugo
in "Posts categorized in ‘hugo’) and forgot to talk about that.
https://www.jakewiesler.com/blog/hugo-taxonomies/ reccomended that you set preserveTaxonomyNames
to true
in your config.toml
at the base of your website.
preserveTaxonomyNames
is removed since Hugo v0.55.
See https://gohugo.io/news/0.55.0-relnotes/ :
preserveTaxonomyNames
configuration option is removed. Use.Page.Title
.
ok, thanks for the update!