mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
add dict.get template tag helper
This commit is contained in:
parent
8a2d4ab68c
commit
013fbf79e9
@ -1,6 +1,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
from typing import Dict, Any
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
from django import template
|
from django import template
|
||||||
@ -238,6 +239,16 @@ def startswith(text: str, starts: str) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def get_key(value: Dict, arg: str) -> Any:
|
||||||
|
"""
|
||||||
|
Template implementation of `dict.get()`, for accessing dict values
|
||||||
|
by key when the key is not able to be used in a template. For
|
||||||
|
example, `{"ui.colormode": "dark"}`.
|
||||||
|
"""
|
||||||
|
return value.get(arg, None)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Tags
|
# Tags
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user