I am trying to generate a table, based on the posts that I have. Now, the challenge here is that this is inside a markdown file, so for each row that I generate, liquid seems to generate a new table for each generated row. Is there a way to fit all rows inside one single table?
Here is my code:
|Title |Link |
|---|---|
{% for my_post in site.posts %}
{% if my_post.title %}
|{{ my_post.title }} |[Click Here]({{ my_post.url }}) |
{% endif %}
{% endfor %}
The generated output looks like this
As you can see, the outcome is actually a messed-up table header row + two separate tables. Can I really generate rows and fit them all inside one table? or am I better off switching to html code?
The liquid markup introduces line breaks in markdown.
Edit : you can now manage use 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 -%}
old answer
If you put your liquid tags on same line you'll have a valid table outputed.
| Title | Link |
|---|---|{% for my_post in site.posts %}{% if my_post.title %}
|{{ my_post.title }} |[Click Here]({{ my_post.url }}) |{% endif %}{% endfor %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With