{# This is the template for a gallery. Expects "gallery_data" and "to_root" as arguments. #}

<DIV class="gallery">
    {% for img_data in gallery_data.values() %}
        {% if img_data.get("status", "ok") == "unprocessed" %}
            <P class="errormsg">Error: gallery data not available.</P>
        {% else %}
            <img src="{{ (img_data["s"]["u"] if "s" in img_data else "", (img_data["p"][-1]["u"]) if img_data.get("p", [])|length > 0 else "")|first_nonzero|rewrite_url(to_root) }}" alt="Image"></img>
        {% endif %}
    {% endfor %}
</DIV>
