Set and read data
Learn how to set local data, and/or read data from Google Sheets or an API.
Last updated
Learn how to set local data, and/or read data from Google Sheets or an API.
Last updated
Set local data that can be used in the template by putting valid JSON inside pairs of ```
or ~~~
, with the data
keyword placed right after the opening pair.
You can have multiple of these data-blocks anywhere on the document, and they will be combined together. In case of key collisions, the data-blocks that come after will override the ones that come before.
You can also read data from a URL using #! get-url = {url}
. By default, CSV is the expected format, and the incoming data is formatted so that each key is a spreadsheet cell reference. This is because by default, Google Sheets is the expected source.
get-objects-name
As you can see above, the rows read from the remote source are available as objects
in the template. However, you can change this reference name to anything you want using the #! get-objects-name = {name}
setting. For example:
get-format
So far, we've been only talking about reading CSV or TSV data from Google Sheets. However, JSON data from a traditional web API is also fully supported. You can read JSON data by setting #! get-format = JSON
, placing your URL in the #! get-url = {url}
, and (optionally) changing the objects reference using #! get-objects-name = {name}
.
Let's read this data and put it on the template:
Full documentation:
For example, here's we want to read:
Apart from directly referencing each cell on your template, you can also go through the rows with a for-loop, especially if your spreadsheet is formatted like an SQL table (first row are the field names). Here's we want to read:
Here, we are reading TSV data by setting the #! get-format = tsv
. Also note, because blocks.md uses , we are able to loop through the objects
that we read from the spreadsheet and output the data on the template.
Let's say we want to read , which returns random JSON data in the following format: