HTML template disappearing

Hi,

I have a problem using the template dashboard node. I hope I can explain it clearly.

I generate the html in the template function node (using mustache) and I feed the output to the template dashboard node. I use this set up a bit everywhere in my flow.

However, I noticed this. There are times that the final html is not displayed in the page when I navigate to the page. It is totally random. I do a deploy and it is there and the next deploy it is just not there. Or, I navigate away from that page and when I navigate back the html is there. Again, totally random. If I inspect the page when the html is not there I found not even 1 line of the html code.

I can give you the code but this happens many times in different cases.

My html page use jquery and javascript too. If not mistaken, I never noticed this behavior with plain html.

Anyone having this problem? Any help would be much appreciated.

When do you feed it to the template? If you deploy the ui-template node then it will not display the html until it is given the html again. So if you use partial deploys this can easily happen.

Hi Colin,

thanks for the reply. I do not use partial deploy (at least, I don't think so). I initialize the flow at start with an inject and the template function feeds the template dashboard at start.

As said, sometimes it works perfectly: it deplois, I see the html page, it works as inteded, and then it just disappears, to appears again. I do not think is a problem of initialization. It looks to me that there is something - maybe in the code - that nodered has problem with.

Here below the code of one of the example I have problem with. I have other example in case.

[
    {
        "id": "680451a6c59fdfab",
        "type": "inject",
        "z": "db9e5b42ac35bf8b",
        "name": "",
        "props": [
            {
                "p": "areas",
                "v": "[{\"name\":\"area1\",\"water\":\"r1_oo1\",\"fire\":\"r1_oo2\",\"hv\":[\"r1_hv1\",\"r1_hv2\"],\"pr\":[\"r1_pr1\",\"r1_pr2\"],\"dw\":[\"r1_dw1\",\"r1_dw2\"]},{\"name\":\"area2\",\"water\":\"r2_oo1\",\"fire\":\"r2_oo2\",\"hv\":[\"r2_hv1\"],\"pr\":[\"r2_pr1\"]},{\"name\":\"area3\",\"water\":\"r3_oo1\",\"fire\":\"r3_oo2\",\"hv\":[\"r3_hv1\",\"r3_hv2\",\"r3_hv3\",\"r3_hv4\"],\"pr\":[\"r3_pr1\",\"r3_pr2\",\"r3_pr3\",\"r3_pr4\"]}]",
                "vt": "json"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "x": 490,
        "y": 300,
        "wires": [
            [
                "6778dc619fed5a9a"
            ]
        ]
    },
    {
        "id": "6778dc619fed5a9a",
        "type": "template",
        "z": "db9e5b42ac35bf8b",
        "name": "",
        "field": "template",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "<style>\n\n</style>\n\n<script>\n(function(scope){ \n\n    let oo_status = {}\n\n    scope.$watch('msg', function(msg) {\n        // Force repaint to adjust to table height\n        if (msg) {\n            $(\"#root\").parent().css(\"height\",\"\");\n        }\n\n        // change oo status\n        if (msg.sensor_type == \"oo\")\n            oo_status[msg.sensor_name] = msg.payload\n\n        // change color\n        if (msg.sensor_name)\n            $(\"#\"+msg.sensor_name).css(\"color\", msg.payload?\"green\":\"red\");\n\n    });\n\n    // pr: payload/state/presence\n    // dw: payload/state/open\n    // hv: payload/config/\n\n    $(\".sensor_oo\").click(function() {\n        let id=$(this).attr(\"id\");\n        oo_status[id] = !oo_status[id]\n        $(\"#\"+id).css(\"color\", oo_status[id]?\"green\":\"red\");\n        scope.send({\n            topic: \"bahf/sensor/\"+id+\"/api/raw/set/onoff/req/1234\",\n            payload:oo_status[id]\n        });\n        console.log(oo_status)\n    });\n\n})(scope);\n</script>\n\n<body>\n<table style=\"width:100%; text-align:left\">\n    <tbody>\n    {{#areas}}\n    <tr>\n        <td style=\"width:20%\" title=\"name\">\n            <span style=\"margin-top: 5px;\">{{name}}</span>\n        </td>\n        <td style=\"width:20%\" title=\"oo\">\n            {{#water}}\n                <span id=\"{{water}}\" class=\"sensor_oo\"><i class=\"fa fa-shower\"></i></span>\n            {{/water}}\n            {{#fire}}\n                <span id=\"{{fire}}\" class=\"sensor_oo\"><i class=\"fa fa-fire\"></i></span>\n            {{/fire}}\n        </td> \n        <td style=\"width:20%\" title=\"hv\">\n            {{#hv}}\n                <span id=\"{{.}}\" class=\"sensor_hv\"><i class=\"fa fa-circle \"></i></span>\n            {{/hv}}\n        </td>\n        <td style=\"width:20%\" title=\"pr\">\n            {{#pr}}\n                <span id=\"{{.}}\" class=\"sensor_pr\"><i class=\"fa fa-user \"></i></span>\n            {{/pr}}\n        </td>\n        <td style=\"width:20%\" title=\"dw\">\n            {{#dw}}\n                <span id=\"{{.}}\" class=\"sensor_dw\"><i class=\"material-icons\">content_copy</i></span>\n            {{/dw}}\n        </td>\n    </tr>\n    {{/areas}}\n    </tbody>\n</table>\n</body>",
        "output": "str",
        "x": 640,
        "y": 380,
        "wires": [
            [
                "c921ab5572becb08"
            ]
        ],
        "info": "<table style=\"width:100%\">\r\n   <tbody>\r\n      <tr>\r\n         <td style=\"width:25%; text-align:left\">\r\narea1\r\n</td>\r\n         <td style=\"width:25%; text-align:left\">\r\n            <table style=\"width:100%\">\r\n               <tbody>\r\n                  <tr>\r\n                     <td style=\"text-align:left\">\r\n                        OO1\r\n                     </td>\r\n                     <td style=\"text-align:left\">\r\n                       OO2\r\n                     </td>\r\n                  </tr>\r\n               </tbody>\r\n            </table>\r\n         </td>\r\n         <td style=\"width:25%; text-align:left\">\r\n            <table>\r\n               <tbody>\r\n                  <tr>\r\n                     <td style=\"text-align:center\">\r\n                        HV1\r\n                     </td>\r\n                     <td style=\"text-align:center\">\r\n                        HV2\r\n                     </td>\r\n                     <td style=\"text-align:center\">\r\n                        HV3\r\n                     </td>\r\n                     <td style=\"text-align:center\">\r\n                        HV4\r\n                     </td>\r\n\t\t\t\t  </tr>\r\n               </tbody>\r\n            </table>\r\n         </td>\r\n         <td style=\"width:25%; text-align:left\">\r\n            <table>\r\n               <tbody>\r\n                  <tr>\r\n                     <td style=\"width:25%; text-align:center\">\r\n                        PR1\r\n                     </td>\r\n                     <td style=\"width:25%; text-align:center\">\r\n                        PR2\r\n                     </td>\r\n\t\t\t\t  </tr>\r\n               </tbody>\r\n            </table>\r\n         </td>\r\n      </tr>\r\n   </tbody>\r\n</table>"
    },
    {
        "id": "c921ab5572becb08",
        "type": "ui_template",
        "z": "db9e5b42ac35bf8b",
        "group": "65907e78a8611bee",
        "name": "template.homepage.area",
        "order": 18,
        "width": "0",
        "height": "0",
        "format": "",
        "storeOutMessages": true,
        "fwdInMessages": false,
        "resendOnRefresh": true,
        "templateScope": "local",
        "x": 950,
        "y": 500,
        "wires": [
            [
                "b2638788fb3a1bf4",
                "6a96fd66e941f0ab"
            ]
        ]
    },
    {
        "id": "65907e78a8611bee",
        "type": "ui_group",
        "name": "Homepage",
        "tab": "4154a19ba5409263",
        "order": 1,
        "disp": false,
        "width": "16",
        "collapse": false
    },
    {
        "id": "4154a19ba5409263",
        "type": "ui_tab",
        "name": "HOMEPAGE",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

Does it make a difference if you get rid of the <body> and </body> tags?

I did not try. I will try now.

What does your Deploy button look like?

I just checked, it is a full deploy (no black node in the button).

@jbudd I tried and the issue is still there. thanks for your help.

Below a printscreen of what is happening. Just to be sure, when I change page from the UI there is no msg sent to the html template: that is, there is not a force refreshed. And, as said before, without doing anything, that html block disappears.

I did not mention this, but there are msg that update the html status. At beginning I thought that was the problem (though the code is correct and the msg is handled properly) but actually if I stop them still the html block still disappears, so it is not them causing this.

chrome_U8S4JaMvBn

Try unchecking Add output messages to stored state in the ui-node.

@E1cid I am trying that. It looks stable. Now I have the problem it does not show the HTML at the deploy, so I have to navigate away and then back. After that it looks stable.

Have you looked at ui-control node to send data when tab is opened?

@E1cid well, that part should work properly. If you see my animated gift, the header is as well a simple template dashboard node and it appears properly, only the other dynamic part with script does not appear at first load.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.