summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2022-01-31 19:26:20 +0100
committerGitHub <noreply@github.com>2022-01-31 19:26:20 +0100
commit3aa1ec3f03a95ad41d3476b92b8b31a68b516b14 (patch)
tree1f263869d27529f44dd16a7dfcd94da4bd15746d /python
parent0a0d4abc02da89f68d453495ec002d2afecfca7b (diff)
parent84d790b65e1356f1c82b2a0e498f834abbe08653 (diff)
downloadvyos-1x-3aa1ec3f03a95ad41d3476b92b8b31a68b516b14.tar.gz
vyos-1x-3aa1ec3f03a95ad41d3476b92b8b31a68b516b14.zip
Merge pull request #1198 from vyos/force_to_list
T4221: add force_to_list Jinja2 filter
Diffstat (limited to 'python')
-rw-r--r--python/vyos/template.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/python/vyos/template.py b/python/vyos/template.py
index 633b28ade..4d081b4c2 100644
--- a/python/vyos/template.py
+++ b/python/vyos/template.py
@@ -127,6 +127,14 @@ def render(
##################################
# Custom template filters follow #
##################################
+@register_filter('force_to_list')
+def force_to_list(value):
+ """ Convert scalars to single-item lists and leave lists untouched """
+ if isinstance(value, list):
+ return value
+ else:
+ return [value]
+
@register_filter('ip_from_cidr')
def ip_from_cidr(prefix):
""" Take an IPv4/IPv6 CIDR host and strip cidr mask.