在前面的内容中定义了标签的示例文章
---
layout : blog
tags: health, covid
---
# COVID-19 vaccines: Get the facts
Looking to get the facts about the new COVID-19 vaccines? Here's what you need to know about the different vaccines and the benefits of getting vaccinated.我希望标签被加入,并在帖子中显示。
有一个名为array_to_sentence_string的过滤器,它基本上连接了文档中记录的所有标签(是的,不需要手动循环每个标签)
https://jekyllrb.com/docs/liquid/filters/
我在代码中使用了{{ page.tags | array_to_sentence_string }}来显示标记。
但是,在构建过程中,我一直收到以下错误消息。
lib/jekyll/filters.rb:153:in `array_to_sentence_string': undefined method `length' for nil:NilClass (NoMethodError)我是不是漏掉了什么?
谢谢
发布于 2021-05-29 17:08:20
更新:我找到了解决方案。我向对象添加了map: 'to_liquid',它就开始工作了。
{{ page.tags | map: 'to_liquid' | array_to_sentence_string }}以下是该页面的完整代码
---
layout: main
---
<h1>{{ page.title }}</h1>
<p class="info">
{{ page.date | date_to_string }}
Tags : {{ page.tags | map: 'to_liquid' | array_to_sentence_string }}
</p>
{{ content }}发布于 2021-06-08 07:43:55
它很可能是你的标签的格式--目前是一个字符串。出于这样的原因,我倾向于避免使用空格分隔的类别和标签格式。尽管您已经找到了一种解决方法,但另一种解决方案可能是将其更改为数组:
tags:
- health
- covidhttps://stackoverflow.com/questions/67748075
复制相似问题