【问题标题】:is not a field of struct type hugolib.SiteInfo in不是结构类型hugolib.SiteInfo的字段
【发布时间】:2017-07-10 02:27:53
【问题描述】:

我尝试向我的theme/partials/footer.html 模板添加一个新属性,并将该属性添加到我的/config.toml 文件中,但我不断收到错误消息:

ERROR: 2017/07/09 template: theme/partials/footer.html:16:40: executing "theme/partials/footer.html" at <.Site.CopyrightStart...>: CopyrightStartYear is not a field of struct type *hugolib.SiteInfo in theme/partials/footer.html

来自我的部分模板文件的示例:

<span>&copy; {{.Site.copyrightStartYear}}</span>

【问题讨论】:

    标签: hugo toml


    【解决方案1】:

    Hugo 中的模板引擎将在 config.toml 文件中的 [Params] 块下查找所有站点参数(在此示例中必须是带引号的字符串)。这些可以通过部分模板中的.Site.Params.&lt;paramName&gt; 查找来引用。

    例如

    # config.toml
    ...
    [Params]
        myParam = "weeee!"
    ...
    

    并在您的 HTML 片段中使用它:

    # somePartial.html
    <span>{{ .Site.Params.myParam }}</span>
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-07
      • 2020-08-26
      • 2020-05-20
      • 2018-10-11
      • 1970-01-01
      • 1970-01-01
      • 2016-02-01
      • 2020-10-14
      相关资源
      最近更新 更多