Add value renderer helper method
This commit is contained in:
1 parent
7acef84aad
commit
d55fda28c2
2 files changed
+27
No files matched your search
@@ -5,9 +5,24 @@ homeassistant.util.template
|
||||
Template utility methods for rendering strings with HA data.
|
||||
"""
|
||||
# pylint: disable=too-few-public-methods
|
||||
import json
|
||||
from jinja2.sandbox import ImmutableSandboxedEnvironment
|
||||
|
||||
|
||||
def render_with_possible_json_value(hass, template, value):
|
||||
""" Renders template with value exposed.
|
||||
If valid JSON will expose value_json too. """
|
||||
variables = {
|
||||
'value': value
|
||||
}
|
||||
try:
|
||||
variables['value_json'] = json.loads(value)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
return render(hass, template, variables)
|
||||
|
||||
|
||||
def render(hass, template, variables=None, **kwargs):
|
||||
""" Render given template. """
|
||||
if variables is not None:
|
||||
|
||||
Reference in new issue
Block a user