雨果静态站点生成器不渲染数据模板

发布于 2025-02-05 18:52:10 字数 1098 浏览 3 评论 0 原文

我正在尝试显示用户列表,该列表保存在 data/staff.json

[
{
    "name":"John",
    "email": "[email protected]" 
},
{
    "name":"Ringo",
    "email": "[email protected]" 
}

]

/code.md 中显示

{{ range .Site.Data.staff }}
<h2>{{ .name }}</h2>
<p>{{ .email }}</p>
{{end}}

中,该数据假设在 content/posts/staff.md.md < 我所能看到的原因是未读者代码

img

我重现了问题 on github上的源代码

>在实时演示上 通过列表和渲染? 雨果版本0.100.1(最新)

I am trying to display list of users, which is saved in data/staff.json

[
{
    "name":"John",
    "email": "[email protected]" 
},
{
    "name":"Ringo",
    "email": "[email protected]" 
}

]

This data suppose to be displayed in content/posts/staff.md

{{ range .Site.Data.staff }}
<h2>{{ .name }}</h2>
<p>{{ .email }}</p>
{{end}}

But from some reason All I can see is unrendered code

img

I reproduced the problem on live demo and this is my source code on Github

Any idea why I cannot loop through list and render?
Hugo version 0.100.1 (latest)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花之痕靓丽 2025-02-12 18:52:10

基于 hugo docs
在访问资源文件之前,您必须添加$符号

{{ range $.Site.Data.staff }}
<h2>{{ .name }}</h2>
<p>{{ .email }}</p>
{{end}}

Based on Hugo docs
You have to add a $ sign before accessing resource file

{{ range $.Site.Data.staff }}
<h2>{{ .name }}</h2>
<p>{{ .email }}</p>
{{end}}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文