Filter Content Pages by Category Using Taxonomies

I’m attempting to list the names of .md files on a certain page. They must match a certain category (seen below). However, I want the place of the category below (visualdesign) to change based on what the current page title is. For instance, the page that this code is located on is called “Tabs”, I want the category in the code below to change to “tabs”. I’ve tried {{ .Title }} in the place of .visualdesign. Though, I receive an error in my terminal and half of the live webpage disappears.

Here’s the code (located in /layouts/_default/single.html):

<div id="block-menu">
          <a href="/Workforce-StyleGuide/" class="top" style="font-weight: bold;">{{ .Title }}</a><br>
          {{ range first 100 .Site.Taxonomies.categories.visualdesign}}
               <a href="{{ .Page.Permalink }}">{{ .Page.Title }}</a><br>
          {{ end }}

Any thoughts on how I could get this to work?


@guayom I’ve seen you mention some taxonomy things before in the threads. Is this something you’ve encountered or worked with before?

I was just dealing with this problem. You want to dynamically filter taxonomies.
You can find how to do it on this post

@guayom Lol I wrote that post.

@guayom I’ve been trying to set this up as a variable, but I don’t think that will work {{$pageTitle := .Title}}

Lol, sorry, I messed up. Here

Try that approach. It works and it’s easy. I’ll try to post a very detailed post about this later today, in case you have any doubts.

No worries man. Thanks for getting back to me. Yeah, I’m a little unsure about that. Hard to find a solution.

Yeah, it took me several hours to figure it out. For what I read in your OP I think this approach is what you’re looking for. If you read that post completely, you may find the way to achive what you’re looking for. Specially this post
Or hang in there for my post in tips and tricks

Okay, thank you for your help. Do you know if it possible to grab just the categories or tags from just the page you are viewing?

Sure, you an access them through .Params.categories

You can list them as shown here in the docs

Hmm, yeah I’ve tried that. However I receive an error in the Terminal:

ERROR 2017/08/03 17:52:19 Error while rendering "page": template: theme/_default/single.html:51:18: executing "theme/_default/single.html" at <.Params.tags>: range can't iterate over test

The same also applies if I do .Params.categories

Actually, I got that working. Yet the output is in lowercase. I’m looking up a way to grab the title from the category.

You can use the title function to convert them to title case. See here:

Very cool. I’m doing {{title . | urlize }}. Would I have to specify using {{ .Title }}?

You are doing it fine. {{ .Title }} refers to the title of a Page. You said above that you’re getting Categories.

1 Like

Strange, still is lowercase using {{title . | urlize }}.

Urlize makes everything lowercase

Is there another way to grab the title of the category? Like .Page.Title?

… Can’t post more that x-number of replies my first day on here :wink: I figured it out lol. {{ . }} didn’t know that was the output function. All good now. This solved my 6-hour issue. I can post my final snippet in Tips and Tricks if you’d guys like. Thanks again for all of your help :slight_smile:

1 Like

Yeah, that got me too a couple times. Takes some time to get used to that.

1 Like