cevepe
August 28, 2021, 2:29pm
1
I would like to insert IF directly into the text to make the script as simple as possible. How will they advise? This doesn't work:
String text_err = "text-warning";
String text_ok = "text-success";
HTML += "<td class=\"text-right" + (temp == 127.0) text_err : text_ok + "\">" + String(temp) + " °C</td>";
cevepe:
This doesn't work:
What exactly doesn't work ?
There is no if statement in the code that you posted. What exactly are you trying to do ?
cevepe
August 28, 2021, 2:34pm
3
If temp == 127.00, I need to print text_err and vice versa text_ok
I would like to use IF in the text so that I don't have to deal with IF outside. I will have about 25 DS18B20 thermometers there and I want to check the color status.
IF in text:
(temp == 127.0) text_err : text_ok
6v6gt
August 28, 2021, 2:40pm
4
Maybe something like this:
String text_err = "text-warning";
String text_ok = "text-success";
HTML += "<td class=\"text-right" + ((temp == 127.0) ? text_err : text_ok ) + "\">" + String(temp) + " °C</td>";
but search also for "c++ ternary operator"
1 Like
Personally I would keep things simple and as easy to read as possible
String tempText = "text-warning";
if (temp == 127)
{
tempText = "text-error";
}
HTML += "<td class=\"text-right" + tempText + " °C</td>";
In practice I would probably not use a String at all
system
Closed
December 26, 2021, 6:15pm
6
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.