Skip to content

Commit

Permalink
fixing docs for getzola#1753 (getzola#1757)
Browse files Browse the repository at this point in the history
  • Loading branch information
piedoom authored and thomasantony committed Sep 17, 2022
1 parent 7da13b2 commit beb916e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions docs/content/documentation/templates/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,23 +261,29 @@ The method returns a map containing `width`, `height` and `format` (the lowercas
Loads data from a file or URL. Supported file types include *toml*, *json*, *csv* and *bibtex* and only supports UTF-8 encoding.
Any other file type will be loaded as plain text.

The `path` argument specifies the path to the data file, according to the [File Searching Logic](@/documentation/templates/overview.md#file-searching-logic).
The `path` argument specifies the path to a local data file, according to the [File Searching Logic](@/documentation/templates/overview.md#file-searching-logic).

```jinja2
{% set data = load_data(path="content/blog/story/data.toml") %}
```

Alternatively, the `url` argument specifies the location of a remote URL to load.

```jinja2
{% set data = load_data(url="https://en.wikipedia.org/wiki/Commune_of_Paris") %}
```

The optional `required` boolean argument can be set to false so that missing data (HTTP error or local file not found) does not produce an error, but returns a null value instead. However, permission issues with a local file and invalid data that could not be parsed to the requested data format will still produce an error even with `required=false`.

The snippet below outputs the HTML from a Wikipedia page, or "No data found" if the page was not reachable, or did not return a successful HTTP code:

```jinja2
{% set data = load_data(path="https://en.wikipedia.org/wiki/Commune_of_Paris", required=false) %}
{% set data = load_data(url="https://en.wikipedia.org/wiki/Commune_of_Paris", required=false) %}
{% if data %}{{ data | safe }}{% else %}No data found{% endif %}
```

The optional `format` argument allows you to specify and override which data type is contained
within the file specified in the `path` argument. Valid entries are `toml`, `json`, `csv`, `bibtex`
within the specified file or URL. Valid entries are `toml`, `json`, `csv`, `bibtex`
or `plain`. If the `format` argument isn't specified, then the path extension is used.


Expand Down

0 comments on commit beb916e

Please sign in to comment.