Jekyll:如何使用 for 循环在降价内的同一 table 内生成 table 行

Jekyll: How to use for loop to generate table row within the same table inside markdown

我正在尝试根据我的帖子生成 table。现在,这里的挑战是它在降价文件中,因此对于我生成的每一行,liquid 似乎为每个生成的行生成一个新的 table。有没有办法将所有行放入一个 table?

这是我的代码:

|Title  |Link  |
|---|---|
{% for my_post in site.posts %}
  {% if my_post.title %}
|{{ my_post.title }}  |[Click Here]({{ my_post.url }})  |
  {% endif %}
{% endfor %}

生成的输出如下所示

如您所见,结果实际上是 messed-up table header 行 + 两个单独的 table。我真的可以生成行并将它们全部放在一个 table 中吗?还是我最好切换到 html 代码?

流式标记在降价中引入了换行符。

编辑: 您现在可以管理使用 whitespace control in Liquid

In Liquid, you can include a hyphen in your tag syntax {{-, -}}, {%-, and -%} to strip whitespace from the left or right side of a rendered tag.

|Title  |Link  |
|---|---|
{% for my_post in site.posts -%}
{% if my_post.title -%}
|{{ my_post.title }}  |[Click Here]({{ my_post.url }})  |
{% endif %}
{%- endfor -%}

旧答案

如果您将液体标签放在同一行,您将得到有效的 table 输出。

| Title | Link |
|---|---|{% for my_post in site.posts %}{% if my_post.title %}
|{{ my_post.title }}  |[Click Here]({{ my_post.url }})  |{% endif %}{% endfor %}