From 5be1126080643428054efe2dd7959922b2bcf6c0 Mon Sep 17 00:00:00 2001 From: Just van den Broecke Date: Sun, 9 Jun 2019 12:12:55 +0200 Subject: [PATCH] fixes #134 render item attr image URL as image thumb element (#163) * #134 render item attr image URL as image thumb element * #134 render item attr image URL as image thumb element - dont use macros include --- pygeoapi/templates/item.html | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pygeoapi/templates/item.html b/pygeoapi/templates/item.html index 10695bb..6c3c596 100644 --- a/pygeoapi/templates/item.html +++ b/pygeoapi/templates/item.html @@ -1,4 +1,17 @@ {% extends "base.html" %} +{# Optionally renders an img element, otherwise standard value or link rendering #} +{% macro render_item_value(v, width) -%} + {% set val = v | string | trim | lower %} + {% if val|length and + (val.endswith(".jpg") or val.endswith(".jpeg") or val.endswith(".png") or val.endswith(".gif") or val.endswith(".bmp")) + %} + {# Ends with image extension: render img element with link to image #} + + {% else %} + {# All other cases: text or link value #} + {{ v | urlize() }} + {% endif %} +{%- endmacro %} {% block title %}{{ super() }} {{ data['title'] }} {% endblock %} {% block crumbs %}{{ super() }} / Collections @@ -52,7 +65,7 @@ {% else %} - {{ v | urlize(25) }} + {{ render_item_value(v, 80) }} {% endif %} {% endfor %}