diff options
author | Daniil Baturin <daniil@vyos.io> | 2022-01-31 07:52:57 -0500 |
---|---|---|
committer | Daniil Baturin <daniil@vyos.io> | 2022-01-31 07:52:57 -0500 |
commit | 84d790b65e1356f1c82b2a0e498f834abbe08653 (patch) | |
tree | 680f122e0489654b06975eff823e616100a9544b /python | |
parent | f791d3ef4c33a4175813f0c00c41ae20aaa447d0 (diff) | |
download | vyos-1x-84d790b65e1356f1c82b2a0e498f834abbe08653.tar.gz vyos-1x-84d790b65e1356f1c82b2a0e498f834abbe08653.zip |
T4221: add force_to_list Jinja2 filter
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/template.py | 8 |
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. |