-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from charlesrocket/data
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
+++ | ||
title = "Data" | ||
date = 2022-10-01 | ||
[taxonomies] | ||
categories = ["usage"] | ||
tags = ["content", "shortcode"] | ||
[extra] | ||
subtitle = "Data loader" | ||
+++ | ||
|
||
Display data from internal or external sources. | ||
|
||
## Example | ||
|
||
#### Input | ||
|
||
``` | ||
This theme requires **Zola** version {{/* data(src="../theme.toml" type="toml" key="min_version") */}} or later. | ||
``` | ||
|
||
- `src`: the address of the data source (mandatory) | ||
- `type`: the file type of the data source ([supported types](https://www.getzola.org/documentation/templates/overview/#load-data)) | ||
- `key`: an object in the data to display | ||
|
||
#### Output | ||
|
||
This theme requires **Zola** version {{ data(src="../theme.toml" type="toml" key="min_version") }} or later. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{%- if src and key and type %} | ||
{%- if src is matching("^http[s]?://") %} | ||
{% set loaded_data = load_data(url=src, format=type) %} | ||
{%- else %} | ||
{% set loaded_data = load_data(path=src, format=type) %} | ||
{%- endif %} | ||
{{ loaded_data[key] }} | ||
{%- else %} | ||
{%- if src is matching("^http[s]?://") %} | ||
{% set loaded_data = load_data(url=src) %} | ||
{%- else %} | ||
{% set loaded_data = load_data(path=src) %} | ||
{%- endif %} | ||
{{ loaded_data }} | ||
{%- endif %} |