# IsMenuCurrent
> 报告给定 Page 对象是否匹配指定菜单中某个菜单项所关联的 Page 对象。
- 官方英文原文：https://gohugo.io/methods/page/ismenucurrent/
- 本页规范地址：https://hugozh.cn/methods/page/ismenucurrent/
- 最近更新：2026-10-02
- 最后提交：912b1d3 chore(site): 添加 static/CNAME（hugozh.cn），供 GitHub Pages 等平台绑定自定义域名
- 签名：PAGE.IsMenuCurrent MENU MENUENTRY
- 返回类型：bool
- 站点：Hugo 中文文档（https://hugozh.cn/）· 社区维护的非官方中文翻译，如有出入以官方英文原文为准

---
```go-html-template
{{ $currentPage := . }}
{{ range site.Menus.main }}
  {{ if $currentPage.IsMenuCurrent .Menu . }}
    <a class="active" aria-current="page" href="{{ .URL }}">{{ .Name }}</a>
  {{ else if $currentPage.HasMenuCurrent .Menu . }}
    <a class="ancestor" aria-current="true" href="{{ .URL }}">{{ .Name }}</a>
  {{ else }}
    <a href="{{ .URL }}">{{ .Name }}</a>
  {{ end }}
{{ end }}
```

完整示例见[菜单模板][]。

> [!NOTE]
> 使用这个方法时，你要么在前置元数据中定义菜单项，要么在项目配置中定义菜单项时指定 `pageRef` 属性。

[菜单模板]: /templates/menu/#example

