usernein / tailwindcss-template-card

Custom card for Home Assistant that renders html code with TailwindCSS styles into the dashboard
MIT License
49 stars 1 forks source link

Frontend template variables not available #3

Open cooperised opened 10 months ago

cooperised commented 10 months ago

Usually, cards that support jinja templates have access to four special variables: user, browser, config and hash. (The important one to me is user, to customise the card based on who is viewing it.) These are all undefined if used in the tailwindcss-template-card. Is there an easy fix for this?

cooperised commented 10 months ago

On further investigation, this information is available to JavaScript via the hass object, e.g. as hass.user.name. Other template cards, for example the Mushroom template card, make this available explicitly as a user variable by passing it to the template renderer. (This is my first time reading the code for any custom cards, so my terminology may be wrong!)

Not sure how to create the other variables but user should be doable with a one-line change to TailwindTemplateCard.tsx. I'll have a play around and submit a PR if I'm successful.