Closed maxdymond closed 1 year ago
{% set data = yamlload(file="random.yml") %}
{{ data.variables.foo }}
should work?
{% set data = yamlload(file="random.yml") %} {{ data.variables.foo }}
should work?
I don't think it does because the docs say:
Currently functions can be called in two places in templates:
variable block: {{ url_for(name="home") }}
for loop container: {% for i in range(end=5) %}
Trying it I get:
Error { kind: Msg(" --> 1:43
|
1 | {% set data = yamlload(file=\"random.yml\") }
| ^---
|
= expected `or`, `and`, `not`, `<=`, `>=`, `<`, `>`, `==`, `!=`, `+`, `-`, `*`, `/`, `%`, a filter, or `%}` or `-%}`"), source: None })
The docs are outdated, you can definitely call it as a set
, eg https://github.com/getzola/zola/blob/master/docs/templates/shortcodes/gallery.html#L4 in the Zola docs
In your snippet, you are missing the % in the closing brace
Ah yes, stupid typo. Works great, thankyou!
Hi,
I added a custom function
yamlload
which loads a Yaml file into aValue
usingserde_yaml
. I was wondering the most ergonomic way of accessing the fields within it.At the moment I think I'm limited to code like:
for filename "random.yml"
as I tried the
get(key="variables/foo")
syntax from the docs but that didn't appear to work. I also tried{{ yamlload(file="random.yml").variables.foo }}
but that didn't work either.Is there a more ergonomic syntax here?