Using custom summary partial inside custom list partial

update: I am closing this question because I realize now that I didn’t ask it properly, and clarifying it will muddy it more than just closing it and starting fresh with a new question. Thanks to all those who read this

using hugo v0.97.3+extended darwin/arm64 BuildDate=unknown VendorInfo=macports

I have two related questions. First, I have tags assigned to my posts, and have the following templates


|----tags
| |----list.html
| |----summary.html
|----_default
| |----single.html
| |----list.html
| |----baseof.html
| |----summary.html

and the tags/list.html looks like the following

{{ define "main" }}
{{ partial "breadcrumbs.html" . }}

<main class="main list" role="main">
{{- with .Title }}
    <header class="main__header">
        <h1 class="main__title">{{ . }}</h1>
    </header>
{{- end }}

{{- range (.Paginator 100).Pages.ByTitle }}
    {{- .Render "summary" }}
{{- end }}
</main>

{{ partial "pagination.html" . }}
{{ end }}

When I browse to the tag list view, for example, http://site/tags/events, I see the page rendered using tags/list.html, however, the summaries are rendered using _default/summary.html. I would like tags/list.html to use tags/summary.html for the summaries.

In fact, (and here is the second, follow-up question), I would like to use custom summary templates for different kinds of tags. For example, I would like to use tags/event-summary.html for posts that are tagged as events and tags/post-summary.html for all other posts. I have the following frontmatter in my events posts.

---
title: Name of Event
description: Description of Event
date: "2022-05-23T20:45:04+02:00"
conference: Conference Name
location: Location of Conference
dateStartOfEvent: "2022-06-21T07:00:00+02:00"
dateEndOfEvent: "2022-06-21T08:30:00+02:00"
type: event
tags:
  - Events
---

I would like to list the event summaries sorted by dateStartOfEvent, and show their title, description, conference, and location name. So, I would modify tags/list.html to show range like so (pseudo-ish code ahead)

{{ if eq .Params.type "event" }}
    {{- range (.Paginator 100).Pages.ByParam "datestartofevent" }}
        {{- .Render "event-summary" }}
    {{- end }}
{{ else }}
    {{- range (.Paginator 100).Pages.ByTitle }}
        {{- .Render "post-summary" }}
    {{- end }}
{{ - end }}

This way I can customize tags/event-summary.html to show the event information. But, in order for me to test the above code, I have to get tags/list to use the correct summary layout. To be clear, the above doesn’t work at all because it seems Hugo wants a template called summary when using the .Render function. I am stuck and need help to go any further.

Update: I am making some progress in understanding how this all works even though I am still not fully successful. I changed my last bit of code to the following and it works in that, it uses a partial template called event-summary.html that I have placed under the partials directory

{{- range (.Paginator 100).Pages.ByParam "datestartofevent" }}
	{{- partial "event-summary.html" . }}
{{- end }}

So, if I modify my earlier code to the following, it should work

{{ if eq .Type "event" }}
	{{- range (.Paginator 100).Pages.ByParam "datestartofevent" }}
		{{- partial "event-summary.html" . }}
	{{- end }}
{{- else }}
	{{- range (.Paginator 100).Pages.ByTitle }}
		{{- .Render "summary" }}
	{{- end }}
{{ end }}

except, the above doesn’t work because .Type in the context of http://site/tags/events evaluates to “tags”, and of course, if eq .Type "event" is false. In this context, how do I get the value of the current tag being displayed (“events” in this case)?

You should replace {{.Render "summary }} with {{ partial "summary.html" . }}

HTH

Thanks, but sorry, that doesn’t help. I am going to close this question for reasons explained in the updated original post, and re-ask with better info and background.

1 Like