Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions src/panels/developer-tools/template/developer-tools-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ class HaPanelDevTemplate extends LitElement {
}

protected render() {
const type = typeof this._templateResult?.result;
const resultType =
type === "object"
? Array.isArray(this._templateResult?.result)
? "list"
: "dict"
: type;
return html`
<div
class="content ${classMap({
Expand Down Expand Up @@ -141,16 +148,28 @@ class HaPanelDevTemplate extends LitElement {
</div>

<div class="render-pane">
<ha-circular-progress
class="render-spinner"
.active=${this._rendering}
size="small"
></ha-circular-progress>

${this._rendering
? html`<ha-circular-progress
class="render-spinner"
active
size="small"
></ha-circular-progress>`
: ""}
${this._templateResult
? html`${this.hass.localize(
"ui.panel.developer-tools.tabs.templates.result_type"
)}:
${resultType}`
: ""}
<!-- prettier-ignore -->
<pre
class="rendered ${classMap({ error: Boolean(this._error) })}"
><!-- display: block -->${this._error}${this._templateResult
?.result}</pre>
class="rendered ${classMap({
error: Boolean(this._error),
[resultType]: resultType,
})}"
>${this._error}${type === "object"
? JSON.stringify(this._templateResult!.result, null, 2)
: this._templateResult?.result}</pre>
${this._templateResult?.listeners.time
? html`
<p>
Expand Down
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2956,6 +2956,7 @@
"description": "Templates are rendered using the Jinja2 template engine with some Home Assistant specific extensions.",
"editor": "Template editor",
"reset": "Reset to demo template",
"result_type": "Result type",
"jinja_documentation": "Jinja2 template documentation",
"template_extensions": "Home Assistant template extensions",
"unknown_error_template": "Unknown error rendering template",
Expand Down