【问题标题】:Hugo markdown metadataHugo 降价元数据
【发布时间】:2018-05-29 20:17:54
【问题描述】:

我想在网页上显示来自 markdown 文件的元数据,因此我尝试使用变量名称(例如 {{ .Author}} )访问它。

这适用于 .Title 和 .Content 变量,但不适用于其他变量!似乎我错过了如何使用这些的重要细节。使用 .Author 变量,页面上的输出为 { map[]}。

提前致谢

降价文件:

---
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 }}

【问题讨论】:

    标签: yaml markdown metadata hugo toml


    【解决方案1】:

    原来您需要通过 .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 }}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-13
      • 2018-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多