For dashboard 1 i could just edit the value format but this is not possible anymore for the text output in dashboard 2. Is there a simple way i don't see?
I would like to add dimensions after the values, e.g. "value" °C
Edit:
@smanjunath211 I believe @joepavitt is talking about the standard template node in that post, not ui-template.
Indeed I am - I will add this to the ui-text
documentation explicitly as the only example we have now covers rendering a link, but the method is the same
I'd go for CSS option to gain full control over the appearance of the suffix.
So you add a class to the text widget:
And a bit of css to get it done:
.temperature-field .nrdb-ui-text-value::after {
content: "°C";
padding-left: 0.125rem;
vertical-align: super;
font-size: smaller;
line-height: initial;
}
Make a class for all types of suffixes you may need, put them in one ui_template
sorry for jumping the gun.
Using CSS option looks nice especially as i need similar function elsewhere.
But where would i create CSS class?
CSS can be defined in a UI Template node with type "CSS (All Pages)" - Docs
Isn't it a bit of an anti-pattern to include the text to display in CSS? It would certainly be tricky for someone looking at the flow in a couple of years time to work out where the °C comes from.
As the definition says:
In CSS, ::after
creates a pseudo-element that is the last child of the selected element. It is often used to add cosmetic content to an element with the content
property. It is inline by default.
Can't see any anti pattern here
This stays always a case even without CSS involved. To avoid this kind of issues i think the best thing is to name your things so that they say what they are or what they do.
So instead of the temperature-field
maybe then adds-celsius-to-value-field
or something like that. It is different for everyone what makes sense and what is not. No way to predict
I think it is pretty obvious if the display node is preceded by a Template node containing
{{ msg.payload }}°C
If the suffix is defined in a ui_template it is not nearly so obvious. Particularly as I thought it was good practice to put all the CSS in one ui_template, so it won't even be on the same flow tab.
preceded by a Template node containing
{{ msg.payload }}°C
...
Particularly as I thought it was good practice to put all the CSS in one ui_template
This is so true that I can't even argue more.
But what is nice - there's many ways to do things.
{{ msg.payload }}°C
Shouldn't that be
{{ payload }}°C
?
It should - and we now have an example in the documentation too: Text ui-text | Node-RED Dashboard 2.0
Shouldn't that be
{{ payload }}°C
?
Yes, I thought either worked but apparently not.
Unfortunately if you want to show {{payload.toFixed(2)}} °C
, which was also possible in the D1 nodes, and is very often required, then you have to use a function node or JSONata I think.
@hotNipi is toFixed(2)
possible in JSONata?
Sorry, I edited my post after you replied.
I'm also confused that the ui-text node config does not have a field where you can specify what payload you want it to emit.
Isn't that rather odd?
is
toFixed(2)
possible in JSONata?
Yes $formatNumber() You can even add the suffix in the format.
Yes, of course. I knew that. So in fact the Change node is probably the best way of solving the general problem. @joepavitt perhaps it would be useful to include an example of that too.
Unfortunately if you want to show
{{payload.toFixed(2)}} °C
, which was also possible in the D1 nodes, and is very often required, then you have to use a function node or JSONata I think.
Although you wouldn't choose an environment variable to define your temperature units, you don't seem to be able to use a variable in the template node either, the reference to the variable is rendered as a string literal ($HOSTNAME does have a value in this NR setup):
Edit: I RTFM