# Include files from a page

**URL:** <https://zola.discourse.group/t/include-files-from-a-page/62>\
**Category:** Support\
**Created:** [February 24, 2019, 3:41pm UTC](https://zola.discourse.group/t/include-files-from-a-page/62 "2019-02-24T15:41:16Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![digital](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/digital/32/31_2.png) [@digital](https://zola.discourse.group/u/digital)\
**Post date:** [February 24, 2019, 3:41pm UTC](https://zola.discourse.group/t/include-files-from-a-page/62/1 "2019-02-24T15:41:16Z")

</div>

I’d like to make a page that displays the contents of an asset file (text). however, tera doesn’t seem to work in pages, only templates. What is a good way to achieve this?

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [February 25, 2019, 4:30pm UTC](https://zola.discourse.group/t/include-files-from-a-page/62/2 "2019-02-25T16:30:27Z")

</div>

You can use [https://www.getzola.org/documentation/content/shortcodes/](https://www.getzola.org/documentation/content/shortcodes/) for that, combined with the `load_data` Tera function: [https://www.getzola.org/documentation/templates/overview/#load-data](https://www.getzola.org/documentation/templates/overview/#load-data)

---

<div class="post-metadata">

**Author:** ![digital](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/digital/32/31_2.png) [@digital](https://zola.discourse.group/u/digital)\
**Post date:** [February 28, 2019, 3:34pm UTC](https://zola.discourse.group/t/include-files-from-a-page/62/3 "2019-02-28T15:34:17Z")

</div>

I’m having some problems implementing this. here are the files I’m working with [https://gitlab.com/latigid/dinid.net](https://gitlab.com/latigid/dinid.net) and here is the output of `zola build`:

```nohighlight
Building site...
Failed to build the site
Error: Failed to render content of /home/digital/projects/zola-dinid-net/content/test/index.md
Reason: Failed to render sh_load_data shortcode
Reason: Failed to render 'shortcodes/sh_load_data.html'
Reason: Global function 'load_data' not found

```

I’m using version 0.5.1 of zola.

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [February 28, 2019, 5:17pm UTC](https://zola.discourse.group/t/include-files-from-a-page/62/4 "2019-02-28T17:17:05Z")

</div>

Ah yes that’s a bug in 0.5.1, it is already fixed in the `next` branch and will be part of the 0.6.0 release.

---

<div class="post-metadata">

**Author:** ![digital](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/digital/32/31_2.png) [@digital](https://zola.discourse.group/u/digital)\
**Post date:** [February 28, 2019, 8:07pm UTC](https://zola.discourse.group/t/include-files-from-a-page/62/5 "2019-02-28T20:07:30Z")

</div>

It indeed works with the next branch. Thank you for your help!

Edit: and by works means it spits out a different error message. I want to include text (clearsigned human readable list of fingerprints, not structured data), but `load_data` is for structured data. I realize that I didn’t make it very clear that I wanted to include human readable text.  
I tried to use the functions `include` and `get_page` but neither of them are found using the next branch (commit `67ddabfa8b26984620935b1bf66c0a89b162d181`). the next branch can’t even build after-dark, which works fine on master. I assume that `get_page` or `include` should work, right?  
(I updated the repo for my webpage at [https://gitlab.com/latigid/dinid.net](https://gitlab.com/latigid/dinid.net))

error message for my shortcode using branch next:

```nohighlight
Building site...
Failed to build the site
Error: Failed to render content of /home/digital/projects/zola-dinid-net/content/test/index.md
Reason: Failed to render sh_display_file shortcode
Reason: Failed to render 'shortcodes/sh_display_file.html'
Reason: Function 'get_page' not found

```

error message for the page without my shortcode:

```nohighlight
Building site...
-> Creating 3 pages (0 orphan), 0 sections, and processing 0 images
Failed to build the site
Error: Failed to render page '/home/digital/projects/zola-dinid-net/content/some-article.md'
Reason: Failed to render 'after-dark/templates/page.html'
Reason: `get_taxonomy_url` received an unknown taxonomy as kind: categories

```

---

<div class="post-metadata">

**Author:** ![digital](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/digital/32/31_2.png) [@digital](https://zola.discourse.group/u/digital)\
**Post date:** [March 8, 2019, 7:18pm UTC](https://zola.discourse.group/t/include-files-from-a-page/62/6 "2019-03-08T19:18:47Z")

</div>

It doesn’t look like edits generate notifications, so _bump_.  
the issues are still the same.

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [March 11, 2019, 7:47pm UTC](https://zola.discourse.group/t/include-files-from-a-page/62/7 "2019-03-11T19:47:16Z")

</div>

The first issue is normal, you don’t have access to `get_page` in shortcodes as shortcodes are rendered while rendering the markdown of pages themselves.

> [@digital](#):
>
> error message for the page without my shortcode:

Are the taxonomies defined in `config.toml` like shown in [Configuration | Zola](https://www.getzola.org/documentation/getting-started/configuration/)?

> [@digital](#):
>
> (I updated the repo for my webpage at [https://gitlab.com/latigid/dinid.net](https://gitlab.com/latigid/dinid.net))

I get a 404, it probably needs to be set to public.

> [@digital](#):
>
> I want to include text (clearsigned human readable list of fingerprints, not structured data), but `load_data` is for structured data. I realize that I didn’t make it very clear that I wanted to include human readable text.

You can load plain text as well with `load_data`.

---

<div class="post-metadata">

**Author:** ![digital](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/digital/32/31_2.png) [@digital](https://zola.discourse.group/u/digital)\
**Post date:** [March 13, 2019, 5:01pm UTC](https://zola.discourse.group/t/include-files-from-a-page/62/8 "2019-03-13T17:01:15Z")

</div>

> [@keats](#):
>
> I get a 404, it probably needs to be set to public.

oops, fixed

> [@keats](#):
>
> You can load plain text as well with `load_data` .

In that case I must be doing something wrong, when I try to load a file ending in .asc or .txt I get this messag

```plaintext
Building site...
Failed to build the site
Error: Failed to render content of /home/digital/projects/zola-dinid-net/content/test/index.md
Reason: Failed to render sh_display_file shortcode
Reason: Failed to render 'shortcodes/sh_display_file.html'
Reason: Unknown output format asc

```

The same happens with .txt (except for the last line, where asc is replaced by txt).

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [March 13, 2019, 7:47pm UTC](https://zola.discourse.group/t/include-files-from-a-page/62/9 "2019-03-13T19:47:04Z")

</div>

> [@digital](#):
>
> In that case I must be doing something wrong, when I try to load a file ending in .asc or .txt I get this messag

Looking at the code now, it seems that it will load things as plain text when it doesn’t have an extension…? I’ll have a better look later this week but that sounds like a bug

---

<div class="post-metadata">

**Author:** ![digital](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/digital/32/31_2.png) [@digital](https://zola.discourse.group/u/digital)\
**Post date:** [March 15, 2019, 2:02pm UTC](https://zola.discourse.group/t/include-files-from-a-page/62/10 "2019-03-15T14:02:38Z")

</div>

I played around with it a bit more and here are some notable results:

an older version of zola and no extension produced this error:

```nohighlight
Building site...
Failed to build the site
Error: Failed to render content of /home/digital/projects/zola-dinid-net/content/test/index.md
Reason: Failed to render sh_display_file shortcode
Reason: Failed to render 'shortcodes/sh_display_file.html'
Reason: Could not determine format for /home/digital/projects/zola-dinid-net/content/test/keys from extension

```

however with the extension “plain” or adding `format=plain` to the `load_data` call I don’t get errors about this part of the site (I get some related to taxonomies)

I then compiled a newer version of zola, destroying the old binary (didn’t think :/)  
now I zola can’t find the file I’m trying to include, no matter the extension:

```nohighlight
Building site...
Failed to build the site
Error: Failed to render content of /home/digital/projects/zola-dinid-net/content/test/index.md
Reason: Failed to render sh_display_file shortcode
Reason: Failed to render 'shortcodes/sh_display_file.html'
Reason: /home/digital/projects/zola-dinid-net/test/keys doesn't exist

```

I then dug around in the source code a bit:  
`get_output_format_from_args` returns “plain” if `path` can’t be extracted from `data_source`. (which seems wrong)  
`grep 'json, toml' load_data.rs` shows two cases where the format “plain” isn’t documented, and [https://www.getzola.org/documentation/templates/overview/](https://www.getzola.org/documentation/templates/overview/) lists plain in sometimes, but not always.

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [March 15, 2019, 2:14pm UTC](https://zola.discourse.group/t/include-files-from-a-page/62/11 "2019-03-15T14:14:43Z")

</div>

> [@digital](#):
>
> I then compiled a newer version of zola, destroying the old binary (didn’t think :/)  
> now I zola can’t find the file I’m trying to include, no matter the extension:

There was a change recently to have load\_data default from the root path (eg where the config.toml is) instead of the content directory.

I’ll have a look at the format thing later today.

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [March 16, 2019, 9:02am UTC](https://zola.discourse.group/t/include-files-from-a-page/62/12 "2019-03-16T09:02:23Z")

</div>

I have made some changes in the `next` branch:

- file loaded now default to `plain`, even without extensions
- `get_taxonomy_url` has been fixed, that was a big bug, thanks!

---

<div class="post-metadata">

**Author:** ![digital](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/digital/32/31_2.png) [@digital](https://zola.discourse.group/u/digital)\
**Post date:** [March 17, 2019, 2:48pm UTC](https://zola.discourse.group/t/include-files-from-a-page/62/13 "2019-03-17T14:48:51Z")

</div>

Thanks for the fixes, the taxonomy issue is solved!

zola includes the file if it has an .plain extension. If I try to load a file with an unknown extension, zola complains about it (even if I specify `format="plain"`).

I noticed that if I leave out the double quotes (`format=plain`) zola doesn’t recognize the function call and just includes the line in the html, without giving a warning or error. This is misleading, I’d prefer zola to tell me “hey, this looks like a function call but it has incorrect syntax”.

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [March 18, 2019, 9:00am UTC](https://zola.discourse.group/t/include-files-from-a-page/62/14 "2019-03-18T09:00:53Z")

</div>

> [@digital](#):
>
> If I try to load a file with an unknown extension, zola complains about it (even if I specify `format="plain"` ).

Hmm that’s weird I tried your repo with the various files and it seemed to work.

> [@digital](#):
>
> This is misleading, I’d prefer zola to tell me “hey, this looks like a function call but it has incorrect syntax”.

That would be a [Tera](https://github.com/Keats/tera/) issue, not Zola

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [March 22, 2019, 7:44pm UTC](https://zola.discourse.group/t/include-files-from-a-page/62/15 "2019-03-22T19:44:44Z")

</div>

> [@keats](#):
>
> If I try to load a file with an unknown extension, zola complains about it (even if I specify `format="plain"` ).

Sorry about that, it is fixed now.

---

<div class="post-metadata">

**Author:** ![digital](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/digital/32/31_2.png) [@digital](https://zola.discourse.group/u/digital)\
**Post date:** [April 8, 2019, 2:51pm UTC](https://zola.discourse.group/t/include-files-from-a-page/62/16 "2019-04-08T14:51:54Z")

</div>

Sorry for the long wait, offline life was a bit stressful.

Thank you very much for the help, I think everything is fixed now. Yay!
