雨果降价元数据
Hugo markdown metadata
我想在网页上显示降价文件中的元数据,所以我尝试使用变量名(例如 {{ .Author}} )访问它。
这适用于 .Title 和 .Content 变量,但不适用于其他变量!似乎我遗漏了有关如何使用这些的重要细节。使用 .Author 变量,页面上的输出为 { map[]}.
提前致谢
Markdown 文件:
---
title: ABC
author: "Foo Bar"
position: Manager
---
The actual content ...
网页:
{{ range where .Data.Pages "Type" "type"}}
<section>
<div>
<div>
{{ .Title }}<br>
{{ .Content }}
</div>
<div>
{{ .Author }}<br>
{{ .Position }}
</div>
</div>
</section>
{{ end }}
原来您需要通过 .Params 变量访问非标准参数。
相关信息参见https://gohugo.io/variables/page/。
{{ range where .Data.Pages "Type" "type"}}
<section>
<div>
<div>
{{ .Title }}<br>
{{ .Content }}
</div>
<div>
{{ .Params.author }}<br>
{{ .Params.position }}
</div>
</div>
</section>
{{ end }}
我想在网页上显示降价文件中的元数据,所以我尝试使用变量名(例如 {{ .Author}} )访问它。
这适用于 .Title 和 .Content 变量,但不适用于其他变量!似乎我遗漏了有关如何使用这些的重要细节。使用 .Author 变量,页面上的输出为 { map[]}.
提前致谢
Markdown 文件:
---
title: ABC
author: "Foo Bar"
position: Manager
---
The actual content ...
网页:
{{ range where .Data.Pages "Type" "type"}}
<section>
<div>
<div>
{{ .Title }}<br>
{{ .Content }}
</div>
<div>
{{ .Author }}<br>
{{ .Position }}
</div>
</div>
</section>
{{ end }}
原来您需要通过 .Params 变量访问非标准参数。
相关信息参见https://gohugo.io/variables/page/。
{{ range where .Data.Pages "Type" "type"}}
<section>
<div>
<div>
{{ .Title }}<br>
{{ .Content }}
</div>
<div>
{{ .Params.author }}<br>
{{ .Params.position }}
</div>
</div>
</section>
{{ end }}