Conditional call for partial depending on type parameter in frontmatter

I have articles with the following frontmatter:

title: My title
description: "some words bla bla"
date: 2020-10-25
type: "docs"

I would like to implement some partial depending on the value of parameter type, ie. when type = docs

I tried the following code

<aside id="sitemeta">
	{{ partial "topbar.html" . }}
	{{ partial "menu.html" . }}

	{{- if .Params "type" "docs" }}
	{{- partial "docs/post-index.html" . }}
	{{ end }}
</aside>

but I got the following error:

executing "partials/aside.html" at <.Params>: wrong number of args for Params: want 0 got 2

It’s probably a syntax error in the if condition but I can’t figure out how to solve it (sorry I am not a coder).
Some help will be much appreciated

You may want to use another word, because type is reserved by hugo to set the page .Type variable, also it affects your template lookup order for that page.

let’s say we use my_type to for custom params. the conditional is like this:

{{- if eq .Params.my_type "docs" }} 
  {{- partial "docs/post-index.html" . }}
{{ end }}

EDIT: or actually you want to use .Type as conditional then you write it like this:

{{- if eq .Type "docs" }} 
  {{- partial "docs/post-index.html" . }}
{{ end }}

You’re right. I just realized that .Type variable is a standardized Hugo Page variable (I actually use it to get a different template)
However, thanks a lot as your second proposal works perfectly.
You save my time !

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