代码之家  ›  专栏  ›  技术社区  ›  FailedUnitTest

未替换页面变量

  •  1
  • FailedUnitTest  · 技术社区  · 7 年前

    我刚开始使用Hugo和Kiss模板,但我似乎无法让变量发挥作用。

    在我的页面中,我在此处定义了变量imgPad:

    ---
    title: "Hugo Blog on Azure"
    date: 2018-12-09T15:51:09-05:00
    draft: false
    imgPad: 14
    ---
    

    下面,我尝试这样使用它:

    <img alt="Deploy to Static Website" src="img/hugo-blog-on-azure/azure_storage_deploy.png" style="width: 500px; display:block; padding: {{ .imgPad }}"/>
    

    在浏览器中{.imgPad}}不会被任何内容替换。有什么问题吗?

    谢谢

    2 回复  |  直到 7 年前
        1
  •  1
  •   mhhollomon    7 年前

    看看 Page Level Params

    它需要访问为

    {{ .Params.imgpad }}
    

    请注意小写字母。

        2
  •  1
  •   VonC    7 年前

    不适用于我,我在浏览器中得到以下结果:

    <img alt="Successful deployment" src="img/hugo-blog-on-azure/azure_storage_deploy2.png" style="width: 500px; display:block; 
    padding: {{ .Params.imgPad }}">
                        ^^^^^^
    

    还有一个大写字母。
    如上所述 in this thread ,在片段模板中使用, 在首页中,只有小写变量。

    示例:

    ingredients:
      - ingredient: Club Soda
        amount: 4oz
      - ingredient: Gin
        amount: 2oz
      - ingredient: Lemon Juice
        amount: 1oz
      - ingredient: Simple Syrup
        amount: 1tsp
    

    {{ range .Params.ingredients }}
     {{ .ingredient }} {{ .amount }}
    {{ end }}
    

    这里的每个变量都是小写的。