Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert CSV to HTML table with Jekyll/Liquid

I keep forgetting how to do this, and I never find a place that answers it online. Gists usually have pretty decent SEO.

Check out my style GitHub repo where you can see my snippets.

{% assign mydata=site.data.foo %}
<table>
<caption>Table caption</caption>
<thead>
{% for column in mydata[0] %}
<th>{{ column[0] }}</th>
{% endfor %}
</thead>
<tbody>
{% for row in mydata %}
<tr>
{% for cell in row %}
<td>{{ cell[1] }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
<snippet>
<content><![CDATA[
{% assign ${1:mydata}=${2:site.data.foo} %}
<table>
<caption>${3:Table caption}</caption>
<thead>
{% for column in ${1:mydata}[0] %}
<th>{{ column[0] }}</th>
{% endfor %}
</thead>
<tbody>
{% for row in ${1:mydata} %}
<tr>
{% for cell in row %}
<td>{{ cell[1] }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
]]></content>
<tabTrigger>;jekylltable</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
<description>Create Liquid HTML based on Jekyll datafile</description>
</snippet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.