Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Page.GetTerms #6905

Closed
bep opened this issue Feb 17, 2020 · 7 comments · Fixed by #6913
Closed

Add Page.GetTerms #6905

bep opened this issue Feb 17, 2020 · 7 comments · Fixed by #6913
Assignees
Milestone

Comments

@bep
Copy link
Member

bep commented Feb 17, 2020

I will add one more thing to 0.65 if I find a good name for it. This is something I've wanted for a while, and I suspect I'm not alone, but the data structure we had for this made it rather clumsy ...

In the docs, we have this example:

{{ $taxo := "tags" }} <!-- Use the plural form here -->
<ul id="{{ $taxo }}">
    {{ range .Param $taxo }}
        {{ $name := . }}
        {{ with $.Site.GetPage (printf "/%s/%s" $taxo ($name | urlize)) }}
            <li><a href="{{ .Permalink }}">{{ $name }}</a></li>
        {{ end }}
    {{ end }}
</ul>

I want it rewritten to something like:

<ul>
    {{ range (.GetTerms "tags") }}
        <li><a href="{{ .Permalink }}">{{ .LinkTitle }}</a></li>
   {{ end }}
</ul>

I always get confused when thinking about these tax terms, and I have probably contributed my share to this confusion (and no, we're not switching the
page kinds taxonomyTerm and taxonomy...)...

But from the docs about the above:

Within your content templates, you may wish to display the taxonomies that piece of content is assigned to.

Note that the above is different than site.GetPage "tags", which gives you the taxonomy term list page (which lists the terms for all pages).

/cc @regisphilibert @digitalcraftsman @onedrawingperday @budparr @davidsneighbour and gang.

@bep bep added this to the v0.65 milestone Feb 17, 2020
@bep bep self-assigned this Feb 17, 2020
@regisphilibert
Copy link
Member

regisphilibert commented Feb 17, 2020

Oh I'm on your side with this, have been for a long time :)
https://discourse.gohugo.io/t/give-some-love-to-terms-listing/13234

Though in the thread mentioned above I advocate for GetTerms which to me (others might chime in) reads closer to what the function will achieve: Get the terms of X taxonomy.

For me Tags is a Taxonomy wile art is a term from given taxonomy. And beside this (indeed) confusing sentence you quote from the doc, the whole "Film" practical example used in the doc seems to align with my understanding.

@bep
Copy link
Member Author

bep commented Feb 17, 2020

Though in the thread mentioned above I advocate for GetTerms which to me (others might chime in) reads closer to what the function will achieve: Get the terms of X taxonomy.

Yea, that may sound better.

<ul>
    {{ range (.GetTaxonomies "tags") }}
        <li><a href="{{ .Permalink }}">{{ .LinkTitle }}</a></li>
   {{ end }}
</ul>

Or:

<ul>
    {{ range (.GetTerms "tags") }}
        <li><a href="{{ .Permalink }}">{{ .LinkTitle }}</a></li>
   {{ end }}
</ul>


@digitalcraftsman
Copy link
Member

digitalcraftsman commented Feb 17, 2020

Though in the thread mentioned above I advocate for GetTerms which to me (others might chime in) reads closer to what the function will achieve: Get the terms of X taxonomy.

I would favor the proposal of @regisphilibert. From my understanding taxonomies have been the name of a collection of pages which share related terms:

Taxonomy Terms
music genre rock, pop, hip hop, classic
colors red, green, blue

In @bep's initial code example he wants to get the terms of a given taxonomy. Getting the taxonomies of tags doesn't seem to make sense IMHO as we want to display the kind of tags that exist, i.e. the terms.

@bep
Copy link
Member Author

bep commented Feb 18, 2020

OK, GetTermsit is. Thanks for the help!

@bep bep changed the title Add Page.GetTaxonomies Add Page.GetTerms Feb 18, 2020
bep added a commit that referenced this issue Feb 19, 2020
bep added a commit to bep/hugo that referenced this issue Feb 19, 2020
@bep bep mentioned this issue Feb 19, 2020
@bep bep closed this as completed in #6913 Feb 19, 2020
bep added a commit that referenced this issue Feb 19, 2020
@gj52
Copy link

gj52 commented Feb 20, 2020

Hi

{{ range (.GetTerms "categories") }}

does not work for me!

@XHPlus
Copy link

XHPlus commented Apr 26, 2020

It seems that the GetTerms function returns a list with inconsistent order with the original one because of bep@9e7e48d#diff-204b5518c5299155dd3b72a4299751f9R157

@bep

@github-actions
Copy link

github-actions bot commented Feb 3, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants