判断页面类型
使用 .Type 属性
Hugo 会根据内容文件的路径自动设置页面类型(Type)。默认情况下:
- content/posts/下的页面 .Type = “posts”
- 其他直接位于 content/下的页面 .Type = “page”
路径匹配
通过 .File.Path 判断路径:
1
2
3
4
5
| {{ if hasPrefix .File.Path "posts/" }}
<!-- 这是 posts 页面 -->
{{ else }}
<!-- 这是 page 页面 -->
{{ end }}
|