From b0f1191d8fb0e6b056f54d57ab1658d1489b6cba Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 1 Mar 2024 17:34:26 +0000 Subject: [PATCH] Only show listing images if there are some This saves a bit more space for page listings which don't have images --- website/common/models.py | 7 ++++++- website/common/templates/common/listing-item.html | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/website/common/models.py b/website/common/models.py index ad96dbd..ff373c7 100644 --- a/website/common/models.py +++ b/website/common/models.py @@ -263,7 +263,12 @@ class BaseListingPage(RoutablePageMixin, BaseContentPage): def get_context(self, request: HttpRequest) -> dict: context = super().get_context(request) - context["listing_pages"] = self.get_paginator_page() + listing_pages = self.get_paginator_page() + context["listing_pages"] = listing_pages + + # Show listing images if at least 1 page has an image + context["show_listing_images"] = any(p.list_image_url for p in listing_pages) + return context @cached_property diff --git a/website/common/templates/common/listing-item.html b/website/common/templates/common/listing-item.html index 88e5111..ff88641 100644 --- a/website/common/templates/common/listing-item.html +++ b/website/common/templates/common/listing-item.html @@ -1,9 +1,9 @@ {% load wagtailcore_tags wagtail_cache util_tags %} -{% wagtailpagecache FRAGMENT_CACHE_TTL "listing-item" breadcrumbs %} +{% wagtailpagecache FRAGMENT_CACHE_TTL "listing-item" breadcrumbs show_listing_images %}
-
+
{% if page.list_image_url %} {{ page.hero_image_alt }}