# Name
> 返回短代码文件名，不含文件扩展名。
- 官方英文原文：https://gohugo.io/methods/shortcode/name/
- 本页规范地址：https://hugozh.cn/methods/shortcode/name/
- 最近更新：2026-10-02
- 最后提交：912b1d3 chore(site): 添加 static/CNAME（hugozh.cn），供 GitHub Pages 等平台绑定自定义域名
- 签名：SHORTCODE.Name
- 返回类型：string
- 站点：Hugo 中文文档（https://hugozh.cn/）· 社区维护的非官方中文翻译，如有出入以官方英文原文为准

---
`Name` 方法在报告错误时很有用。例如，如果你的短代码需要一个「greeting」参数：

```go-html-template {file="layouts/_shortcodes/myshortcode.html"}
{{ $greeting := "" }}
{{ with .Get "greeting" }}
  {{ $greeting = . }}
{{ else }}
  {{ errorf "The %q shortcode requires a 'greeting' argument. See %s" .Name .Position }}
{{ end }}
```

在没有「greeting」参数时，Hugo 会抛出错误消息并让构建失败：

```text
ERROR The "myshortcode" shortcode requires a 'greeting' argument. See "/home/user/project/content/about.md:11:1"
```

