Table of Contents
Data from CSV
You can create tables from CSV files stored in the _data folder of your just-the-docs site.
Prerequisites
First, create a CSV file in the _data folder. For example, create _data/csv_data.csv with your tabular data.
Basic Usage
To render a table from your CSV file:
First, you will need to assign the CSV data to a variable. The Replace the site.data.csv_data with the name of your CSV file (without the .csv extension):
{% assign csv_data = site.data.csv_data %}
Then, create the table structure:
<table>
<thead>
<tr>
{% for header in csv_data.first %}
<th>{{ header[0] }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in csv_data %}
<tr>
{% for cell in row %}
<td>{{ cell[1] }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
Example Output
| column1 | column2 | empty column | column4 |
|---|---|---|---|
| hello | link | https://mdl.library.utoronto.ca/ | |
| 2 | 3 | () |
Using Multiple CSV Files
To use a different CSV file (e.g., _data/another_data.csv), simply change the file name in the assign statement:
{% assign another_data = site.data.another_data %}
<table>
<thead>
<tr>
{% for header in another_data.first %}
<th>{{ header[0] }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in another_data %}
<tr>
{% for cell in row %}
<td>{{ cell[1] }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
Output from another_data.csv
| another_data_column1 | another_data_column2 |
|---|---|
| hello | |
| data2 |
Table with no header
If your CSV file does not have a header row, you can skip the header section in the table:
<table>
<tbody>
{% for row in csv_data %}
<tr>
{% for cell in row %}
<td>{{ cell[1] }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
Output from no_header_data.csv
| hello | link | https://mdl.library.utoronto.ca/ | |
| 2 | 3 | () |