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?