I am trying aggregate blogs from taxonomies so I can have a list of all related blogs. And I ran into something that looks like a Tera bug, so please, what am I doing wrong?
So, I loop over all categories and add them to W. I use set_global so it is accessible outside of the loop. Here is the apprent bug
I can access W inside the loop (length and iterate)
but outside of loop I can print it with {{W}} and get the right number of objects, but then when trying to do something with it:
Error: Reason: Tried to iterate on a container (`W`) that has a unsupported type
so it is like W changes type as loop finishes.
is it a bug, or more likely, am i just very stupid?
best j
{% set categories = get_taxonomy(kind="category") %}
{% set w=0 %}
{% set W=0 %}
{% for p in page.taxonomies.category %}
{% for i in categories.items %}
{% if i.name== p %}
{% if w==0 %}
{% set_global w=1 %}
{% set_global W=i.pages %}
{%else %}
{% set_global W= W | concat(with=i.pages) %}
{%endif%}
{% set length = W | length %}
<h1>{{ length}}</h1>
{% endif %}
{% endfor %}
{% endfor %}
{{w}}
{{W}}
{% for q in W %}
{% endfor %}
yes, the
{% set W=0 %}
should not make any difference, as W is set in the loop with set_global, but it does make a difference and if you move the file 2022-07-06-who-is-to-blame.md out of content/blog the site renders without problems.
for me, the signs point to something weird happening with the class/type of W inside the loop.
Indeed, my site builds now. I can do a PR for the documentation page if desired, someone may want to do same with taxonomies (and some of the other tricks I came up with)?
Still, while I am not an export in template languages, I think there is something not right about this. Specifically, set_global should set the type/class for the variable, and not depend on it being pre-set like this. It feels like it ends up as something like an array, but not quite, or scope does something weird to the type. Does the Tera variable type correspond to a Rust type?
Ah, so that is the bug, I can see that. Thanks @keats
I have been stupid. Coding in template is different than other languages, and comes with fewer error messages, so I should have been more careful and checked my code better,