使用forloop.last进行判断即可, 示例如下:

1
2
3
4
5
6
7
8
9
{% if page.tags.size > 0 %}
<div>
  <i class="bi bi-tags" aria-hidden="true"></i>
    {% for tag in page.tags %}
      <i class="p-1 text-info-emphasis bg-info-subtle border border-primary-subtle rounded-1">{{ tag }}</i>
      {% unless forloop.last %},{% endunless %}
    {% endfor %}
</div>
{% endif %}

forloop (属性)

Property Description Returns
length The total number of iterations in the loop. number
parentloop The parent forloop object. If the current for loop isn’t nested inside another for loop, then nil is returned. forloop
index The 1-based index of the current iteration. number
index0 The 0-based index of the current iteration. number
rindex The 1-based index of the current iteration, in reverse order. number
rindex0 The 0-based index of the current iteration, in reverse order. number
first Returns true if the current iteration is the first. Returns false if not. boolean
last Returns true if the current iteration is the last. Returns false if not. boolean