Summery partial dependent on category

Hello!

I have been trying to use a different partial on the home page dependent on the category of the post however using a simply if as I would do with standard Hugo doesn’t work.

I would like one category to show all the post content and another to show a truncated version with read more.

Is there a way to get this working?

Im pretty sure this should work

{{ if in .Site.Taxonomies.categories "links" }}
  		{{ partial "link-summary.html" . }}
	{{ else}}
		{{ partial "summary.html" . }}
	{{ end }}

But it doesn’t. No errors just nothing.

I’m still trying to solve this 3 years later!

Well, at least in the above, you’re trying to use a Site level variable when you’re trying to reference a content level parameter. This will work using .Params.categories within the range loop over your pages.

Thanks Jason. Tried a few variations of this to try and deal with the quirkiness of micro.blog being slightly different on some things, but no joy. I was expecting Site.Taxonomies.categories "links" to work, but alas.

.Site.Taxonomies.categories will refer to the list of categories on your site since that’s a site variable. There are .Site and .Page variables – and you’re referring to the global stuff.

See this description

Returns a data structure containing the site’s taxonomy objects, the terms within each taxonomy object, and the pages to which the terms are assigned.

It’s the site’s taxonomies.

Versus here

Returns a map of custom parameters as defined in the front matter of the given page.

or here

Returns a collection of term pages for terms defined on the given page in the given taxonomy, ordered according to the sequence in which they appear in front matter.

You have to use .Page methods to get data that is specific to a piece of content versus .Site methods which are scoped site wide.

To come back to this if other people are looking for the same function, I used {{ if in .Params.categories "the category" }}