2

我正在尝试创建一个短代码,我需要在其中读取资源属性。这是我的简码lbimg.html

{{ $img := $.Page.Resources.GetMatch (.Get "name")}}
{{$img.RelPermalink}}

这就是我使用它的方式:

{{< lbimg name="/images/test.png" >}}

这是我在构建网站时得到的:

未能呈现简码“lbimg”:无法处理简码:“path_to_blog/layouts/shortcodes/lbimg.html:2:6”:模板执行失败:模板:简码/lbimg.html:2:6:执行“简码/ lbimg.html" at : nil 指针评估 resource.Resource.RelPermalink

我不明白这是什么意思,为什么资源是nil

我正在使用Hugo 0.59.1.

内容结构如下:

blog
├── content
│   └── post
│       └── test_post
│           ├── images
│           │   └── test.png
│           └── index.md
└── ...
4

1 回答 1

0

你可以试试这个:

{{< lbimg name="images/test.png" >}}

我的错误类似,但我的问题是没有命名页面文件index.md

于 2020-02-01T03:21:43.093 回答