From 84d790b65e1356f1c82b2a0e498f834abbe08653 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Mon, 31 Jan 2022 07:52:57 -0500 Subject: T4221: add force_to_list Jinja2 filter --- python/vyos/template.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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. -- cgit v1.2.3