Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu entry .Name and .Title do not fall back to page .LinkTitle then .Title #13161

Closed
jmooring opened this issue Dec 18, 2024 · 1 comment · Fixed by #13167
Closed

Menu entry .Name and .Title do not fall back to page .LinkTitle then .Title #13161

jmooring opened this issue Dec 18, 2024 · 1 comment · Fixed by #13167
Assignees
Milestone

Comments

@jmooring
Copy link
Member

jmooring commented Dec 18, 2024

Reference: https://discourse.gohugo.io/t/section-menu-items-with-no-name-are-not-rendered/52778

We made a number of intentional breaking changes in v0.123.0, but I don't think this was one of them.

With v0.122.0 and earlier, if you didn't provide a name field when defining a menu entry in your site configuration:

  • The .Name method would fall back to the page’s LinkTitle then to its Title.
  • The .Title method would fall back to the page's Title.

That doesn't happen with v0.123.0 and later.

Also, with v0.123.0 and later, if the pageRef menu entry field points to a section page, and the name field is not defined, the PageRef method returns an empty string, and more importantly, Page returns nothing.

failing test
func TestFoo(t *testing.T) {
	t.Parallel()

	files := `
-- hugo.toml --
disableKinds = ['rss','sitemap','taxonomy','term']
[[menus.main]]
pageRef = '/p1'
weight = 10
[[menus.main]]
pageRef = '/s1'
weight = 20
-- content/p1.md  --
---
title: P1
---
-- content/s1/_index.md --
---
title: S1
---
-- layouts/_default/single.html --
{{ .Content }}
-- layouts/_default/list.html --
{{ .Content }}
-- layouts/_default/home.html --
{{ range $i, $_ := site.Menus.main }}
  A{{ $i }}: <a href="{{ .URL }}">{{ .Name }}</a>
{{ end }}

{{ range $i, $_ := site.Menus.main }}
  B{{ $i }}: <a href="{{ .URL }}">{{ .Title }}</a>
{{ end }}

{{ range $i, $_ := site.Menus.main }}
  C{{ $i }}: <a href="{{ .URL }}">{{ .PageRef }}</a>
{{ end }}

{{ range $i, $_ := site.Menus.main }}
  D{{ $i }}: <a href="{{ .URL }}">{{ .Page.Title }}</a>
{{ end }}
`

	b := hugolib.Test(t, files)
	b.AssertFileContent("public/index.html",
		`A0: <a href="/p1/">P1</a>`,
		`A1: <a href="/s1/">S1</a>`,
		`B0: <a href="/p1/">P1</a>`,
		`B1: <a href="/s1/">S1</a>`,
		`C0: <a href="/p1/">/p1</a>`,
		`C1: <a href="/s1/">/s1</a>`,
		`D0: <a href="/p1/">P1</a>`,
		`D1: <a href="/s1/">S1</a>`,
	)
}

@bep bep removed the NeedsTriage label Dec 18, 2024
@bep bep added this to the v0.141.0 milestone Dec 18, 2024
@jmooring jmooring self-assigned this Dec 18, 2024
jmooring added a commit to jmooring/hugo that referenced this issue Dec 18, 2024
jmooring added a commit to jmooring/hugo that referenced this issue Dec 18, 2024
jmooring added a commit to jmooring/hugo that referenced this issue Dec 18, 2024
jmooring added a commit to jmooring/hugo that referenced this issue Dec 18, 2024
@bep bep closed this as completed in b3f3294 Dec 19, 2024
@bep bep modified the milestones: v0.141.0, v0.140.1 Dec 19, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants