Headless Bundles together with Taxonomies

I swear, making an entire pseudo-project on Github just to ask a question is a nightmare… >.<

Anyway, I was reading about Headless Bundles as substitutes to Taxonomies and, on top of it, if I got it right, a way to get rid of the Data Files

After a lot of struggling with the concept, I managed to set-up a basic multilingual structure which I used in this demo repository. However, after implementing the “all-in” template for Taxonomies provided in the docs — which I really like to keep so I can build an entire search system from it — I noticed that all sections stopped working, “redirecting” me to the Taxonomy Terms template (/tags).

After MUCH debugging and even a start over I noticed that the culprit was the Taxonomies’ definition in my config.yaml. Taking as an example the Taxonomy Term actors, which would list all actors from all movies, I should be seeing a listing template but what I actually have is the Taxonomy Terms’ rendered again. If comment out that entry, everything works as expected and either /en/actors or /pt/actors now list the only two actors I’ve added as a demonstration (Tom Hanks and Tim Allen).

Can’t Taxonomy Terms coexist with Headless Bundles? If not, what could I do to have the same hierarchically rendered Taxonomy Terms (or close to, even if I have to code each block individually).

[EDIT]

While waiting for an answer, assuming it’s really not possible to have both Taxonomy Terms along with Headless Bundles (well, at least not when their names conflict) I tried to replicate the template from the docs manually in favour of the Headless Bundles and I almost got it right (I think).

It’s already updated on Github as well (template /taxonomy/single.html in hello-friend-ng’s theme folder), of course, and, with it, if you access for example /en/taxonomy (best name I could find >.<) you’ll see the entry Fake Actor created on purpose associated to both movies to the date, however, its headless bundle has been associated only in /content/<LANG>/titles/toy-story-2, not the other one.

The obvious problem here is the inner-most {{ range }} that doesn’t take into account any condition, but of the attempts I tried to make each of the movies to appear under each entry (e.g. movies each actor played a role, movies of each genre and etc) all failed.

It may not be the best approach, but after some thinking, I managed to replicate the mentioned 3-levels (in this case) Taxonomy Template in favour of the Headless Bundles. I’m still unsure if they really can’t coexist together or if it’s just a matter of giving them different names but it works perfectly, as long as the proposed structure and relationships are respected.

And I’m so happy today that I decided to share the feat with the community before the demo repository is sent to the void :smiley:

{{- range (where .Site.Sections "Section" "!=" "bundles") -}}

  {{- $this    := . -}}

  <!--
    Retrieves the Headless Bundle that matches current Hugo's Section
    and builds the Top Level Taxonomy Term
  -->

  {{- with $.Site.GetPage (printf "/bundles/%s" $this.Section ) -}}

    <li data-term="{{- .Title -}}">
      <a href="{{- .Params.permalink | absLangURL -}}">{{- .Title -}}</a>

      <ul>

      <!--
       Iterates over all Regular Pages (i.e. excluding Page Files such as _index.md)
       from each valid Hugo Section to build the Second Level Taxonomy Term
      -->
      {{- range $k, $v := (where $.Site.RegularPages "Section" $this.Section ) -}}

        <!--
         Overwriting `$this` seems to not cause any problems to the inner-most
         `$this.Section` below because, apparently, they hold the same value needed
        -->
        {{- $this = . -}}

        <li data-term="{{- .Title -}}">
          <a href="{{- .Permalink | absLangURL -}}">{{- .Title -}}</a>

          <ul>

            <!--
             Iterates over each Regular Page from the "Titles" Section to build
             the Third Level Taxonomy Term creating a pseudo-recursion linking
             all existent Titles to all of the other Second Level Taxonomy Terms
            -->
            {{- range $k, $v := (where $.Site.RegularPages "Section" "titles" ) -}}

              {{- $bundle := . -}}

              <!--
               First we iterate over the Taxonomy Terms Parameters that matches a Hugo Section
               in order to retrieve the corresponding Headless Bundle
               Then we compare if the Headless Bundle retrieved matches with the Regular Page
               retrieved two `range` above
              -->
              {{- range (index .Params $this.Section) -}}
                {{- with $.Site.GetPage . -}}
                  {{- if eq . $this -}}
              <li data-term="{{- $bundle.Permalink -}}">
                <a href="{{- $bundle.Permalink | absLangURL -}}">{{- $bundle.Title -}}</a>
              </li>
                  {{- end -}}
                {{- end -}}
              {{- end -}}

            {{- end -}}

          </ul>

        </li>
      {{- end -}}
      </ul>

  {{- end -}}

{{- end -}}

</ul>

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