Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
tpl: Fix incorrect template selection order
Fixes #13877
  • Loading branch information
yuhui-liu committed Aug 18, 2025
commit 8ceba30303aaeece39d674e5575e0d3b7c3bc433
6 changes: 6 additions & 0 deletions tpl/tplimpl/templatestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,12 @@ func (s *TemplateStore) insertTemplate2(
replace = subCategory == SubCategoryInline && nkExisting.subCategory == SubCategoryInline
}

if !replace && existingFound && fi != nil && nkExisting.Fi != nil {
// Fix issue #13877.
primarySuffix := s.htmlFormat.MediaType.FirstSuffix.FullSuffix
replace = strings.HasSuffix(fi.Name(), primarySuffix) && !strings.HasSuffix(nkExisting.Fi.Name(), primarySuffix)
}

if !replace && existingFound {
if len(pi.Identifiers()) >= len(nkExisting.PathInfo.Identifiers()) {
// e.g. /pages/home.foo.html and /pages/home.html where foo may be a valid language name in another site.
Expand Down
38 changes: 38 additions & 0 deletions tpl/tplimpl/templatestore_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package tplimpl_test

import (
"testing"

"github.com/gohugoio/hugo/hugolib"
)

func TestIssue13877(t *testing.T) {
t.Parallel()

files := `
-- hugo.toml --
disableKinds = ['home','rss','section','sitemap','taxonomy','term']

[mediaTypes.'text/html']
suffixes = ['b','a','d','c']

[outputFormats.html]
mediaType = 'text/html'
-- content/p1.md --
---
title: p1
---
-- layouts/page.html.a --
{{ templates.Current.Name }}
-- layouts/page.html.b --
{{ templates.Current.Name }}
-- layouts/page.html.c --
{{ templates.Current.Name }}
-- layouts/page.html.d --
{{ templates.Current.Name }}
`

b := hugolib.Test(t, files)

b.AssertFileContent("public/p1/index.b", "page.html.b")
}
Loading