From: Magnus Hagander Date: Tue, 20 Aug 2024 08:33:16 +0000 (+0200) Subject: Add a template tag to access an array by index X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=43f5f188f26a23555a3030c952d7f287e4f6ca55;p=pgeu-system.git Add a template tag to access an array by index For some reason, django won't let us do that from a template, so we have to add our own. --- diff --git a/postgresqleu/confreg/templatetags/miscutil.py b/postgresqleu/confreg/templatetags/miscutil.py index 8711ed27..9c4f16fa 100644 --- a/postgresqleu/confreg/templatetags/miscutil.py +++ b/postgresqleu/confreg/templatetags/miscutil.py @@ -29,3 +29,12 @@ def jsonstruct(value): @register.filter(name='subtract') def subtract(value, arg): return value - arg + + +@register.simple_tag(name='arrayindex') +def arayindex(value, arg, mod=None): + if mod: + arg = arg + mod + if arg < len(value): + return value[arg] + return ''