Skip to content

Commit

Permalink
Merge pull request #13 from charlesrocket/data
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesrocket authored Feb 7, 2024
2 parents 317ca8e + 88d3538 commit 18c7642
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
27 changes: 27 additions & 0 deletions content/posts/data/index.md
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.
15 changes: 15 additions & 0 deletions templates/shortcodes/data.html
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 %}

0 comments on commit 18c7642

Please sign in to comment.