I have spent multiple hours today working on this.
I'm using a mustache template node to render a database query results page as HTML.
I think what I want is simple ... if the string in the return value contains an 'h' then change the background color of that cell to light red/pink.
I have tried all sorts of things and can't get anything to work. I even asked, or tried to, Chat GPT about it and got nothing that would even come close to running. GPT was trying to get me to create script functions and call them from mustache in a way that was very confusing to me. It looked like it was trying to building the page "in memory" then when it was all done it would "render" it as HTML. I could not understand what it was doing and the "explanation" was even more confusing.
Here is a simple sample of what I'm trying to do. Very simple data set and page.
[
{
"id": "d115287648de5277",
"type": "inject",
"z": "923dd5a9f9e0a06a",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "[{\"w1\":\"This\",\"w2\":\"is\",\"w3\":\"Big!\"},{\"w1\":\"Big\",\"w2\":\"as\",\"w3\":\"this?\"}]",
"payloadType": "json",
"x": 110,
"y": 80,
"wires": [
[
"02a317e4972a9954"
]
]
},
{
"id": "8c71a0febf7bcd4d",
"type": "debug",
"z": "923dd5a9f9e0a06a",
"name": "debug 8",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 660,
"y": 60,
"wires": []
},
{
"id": "3cef1bf1ead9baa3",
"type": "http in",
"z": "923dd5a9f9e0a06a",
"name": "",
"url": "/ws2/test",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 130,
"y": 120,
"wires": [
[
"6d20ca2e5c43ccaf"
]
]
},
{
"id": "6c988531eedbd0c3",
"type": "http response",
"z": "923dd5a9f9e0a06a",
"name": "",
"statusCode": "",
"headers": {},
"x": 650,
"y": 100,
"wires": []
},
{
"id": "6d20ca2e5c43ccaf",
"type": "function",
"z": "923dd5a9f9e0a06a",
"name": "function 2",
"func": "var data = [\n { \"w1\": \"This\", \"w2\": \"is\", \"w3\": \"Big!\" },\n { \"w1\": \"Big\", \"w2\": \"as\", \"w3\": \"this?\" }\n];\n\nmsg.payload = data;\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 300,
"y": 120,
"wires": [
[
"02a317e4972a9954"
]
]
},
{
"id": "02a317e4972a9954",
"type": "template",
"z": "923dd5a9f9e0a06a",
"name": "",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <title>\n Moustache Test\n </title>\n <style>\n table, td, th {\n text-align:center;\n font-family:monospace;\n font-size: 16px;\n }\n td { width: 70px; }\n </style>\n </head>\n <body>\n <h3>\n <center>\n Moustache Test Page\n </center>\n </h3>\n <table align=\"center\">\n <tr>\n <td>Word 1</td><td>Word 2</td><td>Word 3</td>\n </tr>\n {{#payload}}\n <tr>\n <td bgcolor=\"{{ '{{w1}}'.includes('h') ? '#FFC0CB' : '' }}\">{{w1}}</td>\n <td bgcolor='#FFC0CB'>{{w2}}</td>\n <td bgcolor=\"{{w3}}.includes('h') ? '#FFC0CB' : ''\">{{w3}}</td>\n </tr>\n {{/payload}}\n </table>\n </body>\n</html>\n",
"output": "str",
"x": 480,
"y": 80,
"wires": [
[
"8c71a0febf7bcd4d",
"6c988531eedbd0c3"
]
]
},
{
"id": "58e1af2d0f632963",
"type": "comment",
"z": "923dd5a9f9e0a06a",
"name": "Description",
"info": "What I want to do sounds simple.\nIf the string data has a 'h' in it then I want the back ground of the cell\nto be a light red / pink, otherwise white as the default.\n\nI have tried all sort of ways and even asked GPT (or tried to, I never got\nthe question close enough to give me workable code.)\n",
"x": 300,
"y": 60,
"wires": []
}
]