Add count param to cart mini macro for explicit override

When the macro is imported without context ({% from ... import mini %}),
template variables like cart_count aren't visible. The new count param
allows callers to pass it explicitly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-21 09:42:58 +00:00
parent 1f8fb521b2
commit 7abef48cf2

View File

@@ -1,9 +1,12 @@
{% macro mini(oob=False) %} {% macro mini(oob=False, count=None) %}
<div id="cart-mini" {% if oob %}hx-swap-oob="{{oob}}"{% endif %} > <div id="cart-mini" {% if oob %}hx-swap-oob="{{oob}}"{% endif %} >
{# cart_count is set by the context processor in all apps. {# cart_count is set by the context processor in all apps.
Cart app computes it from g.cart + calendar_cart_entries; Cart app computes it from g.cart + calendar_cart_entries;
other apps get it from the cart internal API. #} other apps get it from the cart internal API.
{% if cart_count is defined and cart_count is not none %} count param allows explicit override when macro is imported without context. #}
{% if count is not none %}
{% set _count = count %}
{% elif cart_count is defined and cart_count is not none %}
{% set _count = cart_count %} {% set _count = cart_count %}
{% elif cart is defined and cart is not none %} {% elif cart is defined and cart is not none %}
{% set _count = (cart | sum(attribute="quantity")) + ((calendar_cart_entries | length) if calendar_cart_entries else 0) %} {% set _count = (cart | sum(attribute="quantity")) + ((calendar_cart_entries | length) if calendar_cart_entries else 0) %}