best way to capitalize a string in js, use a function #219
-
for several info texts I use a template that returns a lowercase string example:
but I want it to be displayed capitalized. Jinja has that function and filter with
would you think this is the best way to go, or could we maybe install the function first as some generic method in the config, to be able to call it in other templates too? not sure where we could do that, but in it would be something like:
and then use it with:
given this would be used throughout the config and not in a singled out dashboard, I can not use it as partial. or, would be even better.... have the function built in into the plugin ? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes, you are already doing it in the right way. There are many ways in which you can write such a function, this is just one of them (remember that you can include a partial inside another partial): js_variables:
trash: sensor.afvalwijzer_vandaag
temperature: sensor.temperature
partials:
utilities: |
const capitalize = str => str[0].toUpperCase() + str.slice(1);
data: |
@partial utilities
const afval = capitalize(states(trash));
order:
- item: something
name: |
[[[
@partial data
return afval;
]]]
info: |
[[[
@partial utilities
return capitalize(states(temperature));
]]] |
Beta Was this translation helpful? Give feedback.
Yes, you are already doing it in the right way. There are many ways in which you can write such a function, this is just one of them (remember that you can include a partial inside another partial):