Include files from a page

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?

You can use 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

1 Like

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

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.

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.

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)

error message for my shortcode using branch next:

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:

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
1 Like

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

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.

Are the taxonomies defined in config.toml like shown in Configuration | Zola?

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

You can load plain text as well with load_data.

oops, fixed

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

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).

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

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:

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:

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/ lists plain in sometimes, but not always.

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.

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!
1 Like

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”.

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

That would be a Tera issue, not Zola

Sorry about that, it is fixed now.

1 Like

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!

1 Like