zola
zola copied to clipboard
How do I make use of throw?
Documentation issue
The feature was merged here: https://github.com/Keats/tera/pull/310
The documentation is here: https://keats.github.io/tera/docs/#throw
Summary
In the abridge theme when a user omits a required value in config.toml I would like to throw a specific error.
For instance the Abridge theme requires that compiles_sass is set to true, without it they see this error message:
Error: Failed to build the site
Error: Failed to render pager 1
Error: Reason: Failed to render 'index.html' (error happened in 'base.html').
Error: Reason: Function call 'get_url' failed
Error: Reason: `get_url`: Could not find or open file abridge.css
For a novice I think it would be best to explain exactly why they are seeing this error, which is that they simply need to set compiles_sass to true in config.toml
Here is what I have tried:
{%- if config.compile_sass %}
{%- set stylesheets=config.extra.stylesheets | default(value=[ "abridge.css" ]) -%}
{%- if stylesheets %}{%- for i in stylesheets %}
<link rel="stylesheet" href="{{ get_url(path=i , trailing_slash=false, cachebust=true) | safe }}" />
{%- endfor %}{%- endif %}
{%- else %}
{% throw(message="Error: Theme requires that compile_sass is set to true in config.toml") %}
{%- endif %}
but it does not seem to work, I get the following error:
zola serve
Building site...
Error: Failed to serve the site
Error: Error parsing templates from the /templates directory
Error: Reason:
* Failed to parse "/home/jieiku/.dev/test/abridge/templates/partials/head.html"
--> 25:5
|
25 | {% throw(message="Error: Theme requires that compile_sass is set to true in config.toml") %}
| ^---
|
= unexpected tag; expected an endif tag (`{% endif %}`) or some content
UPDATE: I just found another issue as well. It seems I cannot actually check the value of config.compile_sass from a template so I believe it is not exposed as a value you can check.
Proposed solution
I think it would be good to give a short example of how to use throw() on the tera or zola documentation sites. I am guessing however that I did this correctly and it simply is not working anymore. I really appreciate any help with this.