如何根据 Jekyll 类别创建 IF 语句?

ast*_*ush 1 jekyll

<body>如果帖子属于“文章”类别,我想有条件地添加一个类。我尝试了以下方法:

<body
  {% if page.categories == article %}
    class="article"
  {% endif %}
>
Run Code Online (Sandbox Code Playgroud)

奇怪的是,这将“文章”类放置在除文章帖子之外的每个页面上。

Dav*_*uel 6

使用contains

<body {% if page.categories contains "jekyll" %} class="article"{% endif %}>
Run Code Online (Sandbox Code Playgroud)

全部在一行上,否则标签中将会出现换行符。