Get page for taxonomy!

Im trying to get the page for a specific taxonomy when I’m building breadcrumbs… I’m struggling to get the page when all I have is the URL of the page… let me explain…

I have a custom taxonomy of course-topics set in my hugo.yml:

taxonomies:
  course-topic: course-topics

permalinks:
  taxonomy:
    course-topics: "/capabilities/training-courses/course-topics"
  term:
    course-topics: "/capabilities/training-courses/:slug/"
  page:
    course: /:sections/:slug/

My course has course-topics set and all is good. I have hard coded the course-topics URL into my course url so that its listed under it as I cant add :course-topics to the format… this is fine.

---
type: course
slug: practicing-kanban-using-azure-boards-training
url: /capabilities/training-courses/azure-devops-training-courses/:slug/
course-topics:
  - Azure DevOps Training  Courses
---

I build breadcrumbs, and the default behaviour of walking the parents will not work so I’ve created a custom render if its course or course-topics… works create for course-topics but the course is missing the course-topics from the URL.

    <!-- Custom breadcrumb for taxonomy terms like 'course-topic' -->
    {{ if or (eq .Type "course") (eq .Type "course-topics") (eq .Type "course-vendors") }}
      <!-- Manually construct the parent hierarchy for taxonomies -->
      {{ $breadcrumbs = $breadcrumbs | append (site.GetPage "home") }}
      {{ $breadcrumbs = $breadcrumbs | append (site.GetPage "capabilities") }}
      {{ $breadcrumbs = $breadcrumbs | append (site.GetPage "capabilities/training-courses") }}
      {{ if eq .Type "course" }}
        {{ $urlParts := split .Params.url "/" }}
        {{ $courseTopic := index $urlParts 3 }}
        {{ $search := (printf "term/course-topics/%s" $courseTopic) }}
        {{ $termPage := site.GetPage $search }}
        {{ $termPage }}
        {{ if $termPage }}
          <!-- Add the term page to the breadcrumbs -->
          {{ $breadcrumbs = $breadcrumbs | append $termPage }}
        {{ end }}
      {{ end }}
      {{ $breadcrumbs = $breadcrumbs | append . }}
      {{ $built = true }}
    {{ end }}

What I’m stuck on is the correct format for getting the term page within my context… I’ve tried what seems to be documented:

{{ $termPage := site.GetPage "taxonomyTerm/course-topics/azure-devops-training-courses" }}

Also tried the relative path that its rendered to:

{{ $termPage := site.GetPage "capabilities/training-courses/azure-devops-training-courses/" }}

I seem to be missing something! What is it?

Does capabilities/training-courses/azure-devops-training-courses exist in your content folder? If not, that’s probably the reason.

Another thing I noted is that you have two spaces in your sample in Training Courses… just in case that typo exists in real world.

To my knowledge site.GetPage only works if the page exists. You can always add that file as described in the documentation. If you do that you could transform your course-topic into something more usable like azure-devops-training-courses and then in content/course-topic/azure-devops-training-courses/_index.md (underscore!!!) you can define a title that is shown when you parse that tag.

1 Like

Im not able to get it to load the _index.md for the term!

I created site\content\course-topics\azure-devops-training-courses\_index.md but it has no effect on on the data available on the term page.

note: Also fices the double space thing.

I haven’t looked at this in detail, and the approach seems a bit complex. In any case, this doesn’t look right to me:

{{ $search := (printf "term/course-topics/%s" $courseTopic) }}

Why are you prepending the word “term”?

Also, there’s no need to wrap the expression within parentheses.

Works both with and without term … thanks…

Does that mean you solved your issue?

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