From 2d41c9963d0f39621706e7b40d85504d7493ca7a Mon Sep 17 00:00:00 2001 From: Thomas Rusiecki Date: Wed, 26 Feb 2025 23:44:49 -0300 Subject: [PATCH] templatetag for left menu active item management --- dashboard/templates/base.html | 93 ++++++++++++++++++---------- dashboard/templatetags/startswith.py | 9 +++ 2 files changed, 68 insertions(+), 34 deletions(-) create mode 100644 dashboard/templatetags/startswith.py diff --git a/dashboard/templates/base.html b/dashboard/templates/base.html index 1cd0932..2123b5e 100644 --- a/dashboard/templates/base.html +++ b/dashboard/templates/base.html @@ -1,4 +1,4 @@ -{% load i18n static %} +{% load i18n static startswith %} @@ -80,97 +80,122 @@ diff --git a/dashboard/templatetags/startswith.py b/dashboard/templatetags/startswith.py new file mode 100644 index 0000000..62d0867 --- /dev/null +++ b/dashboard/templatetags/startswith.py @@ -0,0 +1,9 @@ +#https://medium.com/@malvin.lok/add-a-custom-function-startwith-on-the-django-template-f11e1916f0d1 +from django import template + +register = template.Library() + + +@register.filter('startswith') +def startswith(value, prefixes): + return any(value.startswith(prefix) for prefix in prefixes.split(','))