I’ve started adding support for Tera v2 in Zola and I’ve had to look at that beast of a function again working for both local and remote files.
I think I like the Hugo approach a bit more there, where you have a global data folder loaded once and accessible from anywhere rather than doing it from the templates. We could also add a data field so colocated pages can automatically load some data files.
We can add a fetch_json function for HTTP calls.
Are there usecases not covered by the approach above? Any obvious downsides?
where you have a global data folder loaded once and accessible from anywhere rather than doing it from the templates
Would pages/sections lose the ability to colocate their data in the same directory?
Does “accessible from anywhere” just mean a global path or something else?
API
We can add a fetch_json function for HTTP calls.
Since fetch is already a web standard why not reuse that but pipe the output to a filter to handle different formats?
{{ set json_obj = fetch(url=”…”) | as_json }}
{{ set json_toml = fetch(url=”…”) | as_toml }}
{{ set txt = fetch(url=”…”) | get_body }}
For local files there isn’t a standard, but every language binding uses the word read so maybe that should be reused? You could reuse the same filters as fetch above.
{{ set json_obj = read(path=”…”) | to_json }}
{{ set json_toml = read(path=”…”) | to_toml }}
{{ set txt = read(path=”…”) }}
Nope the opposite actually, you will be able to load the data files before rendering the markdown so the data should be available at that time.
Probably a global data field accessible from all templates.
I like the names fetch/read. I’ll do a more detailed RFC after 0.23 as there’s already way more than enough on my plate right now. The idea of this thread is to collect some usage patterns to avoid xkcd: Workflow