You'll need to have one ui_template
per dashboard tab. Not per group.
And no, it can't be done with the script added to the head.
Try this approach.
[
{
"id": "d365d02956b1c509",
"type": "ui_template",
"z": "8679b7e94e378141",
"group": "c86213fc1aa53032",
"name": "top-bar",
"order": 1,
"width": 0,
"height": 0,
"format": "<style>\n#top-bar-logo {\n background-image: url(https://nodered.org/about/resources/media/node-red-icon-2.png);\n background-size: contain;\n background-repeat: no-repeat;\n background-position: center;\n height: 100%;\n width: 100%;\n}\n\n.top-bar-txt{\n margin-left:10px;\n}\n</style>\n\n<script id=\"logo-script\" type=\"text/javascript\">\nvar ready = false\nvar titleText\nvar timeText\n\nfunction build(){\n $(\"#top-bar-logo\").remove();\n $(\"#top-bar-title\").remove();\n $(\"#top-bar-clock\").remove();\n var topbar = $('.md-toolbar-tools');\n $('<div />').attr(\"id\",\"top-bar-logo\").appendTo(topbar);\n $('<div />').attr({id:\"top-bar-title\",class:\"top-bar-txt\"}).appendTo(topbar); \n $('<div />').attr({id:\"top-bar-clock\",class:\"top-bar-txt\"}).appendTo(topbar); \n}\n// these functions can be called any time from server side\n// if DOM is not ready, just store the variable\nfunction updateTitleText(txt){ \n if(txt){\n titleText = txt\n } \n if(!ready){\n return\n }\n $(\"#top-bar-title\").text(titleText)\n}\n\nfunction showTime(time){\n if(time){\n timeText = time\n }\n if(!ready){\n return\n }\n $(\"#top-bar-clock\").text(timeText)\n}\n\nfunction checkExistence(){\n if($(\"#top-bar-logo\").length > 0){\n ready = true\n // call updateTitle cos server may have called it before DOM is ready \n updateTitleText()\n showTime()\n return\n }\n build()\n setTimeout(checkExistence,100)\n}\n\nbuild()\nsetTimeout(checkExistence,100)\n\n// expose api's\nwindow.TopBar = {\n updateTitle: updateTitleText,\n updateTime:showTime\n}\n</script>\n",
"storeOutMessages": true,
"fwdInMessages": true,
"resendOnRefresh": true,
"templateScope": "global",
"x": 820,
"y": 100,
"wires": [
[]
]
},
{
"id": "0d2d2837d831c64d",
"type": "change",
"z": "8679b7e94e378141",
"name": "",
"rules": [
{
"t": "set",
"p": "title",
"pt": "global",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 400,
"y": 480,
"wires": [
[
"0156f9cb255d8b94"
]
]
},
{
"id": "596dfd22b9de5f34",
"type": "ui_template",
"z": "8679b7e94e378141",
"group": "c86213fc1aa53032",
"name": "tab home",
"order": 2,
"width": 0,
"height": 0,
"format": "<script>\n (function(scope) {\n scope.$watch('msg', function(msg) {\n if (msg) {\n // call exposed api's \n if(msg.topic == \"title\"){\n window.TopBar.updateTitle(msg.payload)\n }\n if(msg.topic == \"clock\"){\n window.TopBar.updateTime(msg.payload)\n }\n }\n });\n})(scope);\n</script>",
"storeOutMessages": true,
"fwdInMessages": true,
"resendOnRefresh": true,
"templateScope": "local",
"x": 820,
"y": 260,
"wires": [
[]
]
},
{
"id": "f1d2e25d96a66a3e",
"type": "ui_ui_control",
"z": "8679b7e94e378141",
"name": "",
"events": "connect",
"x": 200,
"y": 240,
"wires": [
[
"0156f9cb255d8b94"
]
]
},
{
"id": "0156f9cb255d8b94",
"type": "change",
"z": "8679b7e94e378141",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "title",
"tot": "global"
},
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "title",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 580,
"y": 240,
"wires": [
[
"596dfd22b9de5f34",
"262cd01de1963b1b"
]
]
},
{
"id": "262cd01de1963b1b",
"type": "ui_template",
"z": "8679b7e94e378141",
"group": "c3089136b03388ac",
"name": "tab away",
"order": 2,
"width": 0,
"height": 0,
"format": "<script>\n (function(scope) {\n scope.$watch('msg', function(msg) {\n if (msg) {\n // call exposed api's \n if(msg.topic == \"title\"){\n window.TopBar.updateTitle(msg.payload)\n }\n if(msg.topic == \"clock\"){\n window.TopBar.updateTime(msg.payload)\n }\n }\n });\n})(scope);\n</script>",
"storeOutMessages": true,
"fwdInMessages": true,
"resendOnRefresh": true,
"templateScope": "local",
"x": 820,
"y": 300,
"wires": [
[]
]
},
{
"id": "e68d7fe1a3146ffc",
"type": "change",
"z": "8679b7e94e378141",
"name": "set global title default",
"rules": [
{
"t": "set",
"p": "title",
"pt": "global",
"to": "Dafault title",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 580,
"y": 100,
"wires": [
[]
]
},
{
"id": "bb8800dff1ed5f15",
"type": "inject",
"z": "8679b7e94e378141",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"payloadType": "date",
"x": 210,
"y": 100,
"wires": [
[
"5a3048153bd90c21"
]
]
},
{
"id": "5a3048153bd90c21",
"type": "switch",
"z": "8679b7e94e378141",
"name": "",
"property": "title",
"propertyType": "global",
"rules": [
{
"t": "null"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 360,
"y": 100,
"wires": [
[
"e68d7fe1a3146ffc"
]
]
},
{
"id": "aab446fc2fa8a22c",
"type": "comment",
"z": "8679b7e94e378141",
"name": "if there is no global.title, set default title",
"info": "",
"x": 480,
"y": 60,
"wires": []
},
{
"id": "0aaa712077fe07a1",
"type": "comment",
"z": "8679b7e94e378141",
"name": "when dashboard connects, send global.title",
"info": "",
"x": 280,
"y": 280,
"wires": []
},
{
"id": "a5a02443a3c61f3e",
"type": "comment",
"z": "8679b7e94e378141",
"name": "set global.title and send it ",
"info": "",
"x": 430,
"y": 520,
"wires": []
},
{
"id": "53b3b933aab13765",
"type": "comment",
"z": "8679b7e94e378141",
"name": "msg's can be listened only if ui_tempalte is in group",
"info": "",
"x": 830,
"y": 340,
"wires": []
},
{
"id": "cd4df33c036b6abd",
"type": "comment",
"z": "8679b7e94e378141",
"name": "script in head",
"info": "",
"x": 820,
"y": 60,
"wires": []
},
{
"id": "9482ed753c57d241",
"type": "comment",
"z": "8679b7e94e378141",
"name": "script for every tab (content is same for all)",
"info": "",
"x": 920,
"y": 220,
"wires": []
},
{
"id": "787191d686846f20",
"type": "function",
"z": "8679b7e94e378141",
"name": "clock",
"func": "function checkTime(i) {\n if (i < 10) { i = \"0\" + i };\n return i;\n}\nconst today = new Date();\nlet h = today.getHours();\nlet m = today.getMinutes();\nlet s = today.getSeconds();\nm = checkTime(m);\ns = checkTime(s);\nmsg.payload = h + \":\" + m + \":\" + s;\nmsg.topic = \"clock\"\nreturn msg",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 610,
"y": 200,
"wires": [
[
"596dfd22b9de5f34",
"262cd01de1963b1b"
]
]
},
{
"id": "5f61610f2a29b432",
"type": "inject",
"z": "8679b7e94e378141",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "1",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payloadType": "date",
"x": 210,
"y": 200,
"wires": [
[
"787191d686846f20"
]
]
},
{
"id": "6a07b007c072a673",
"type": "group",
"z": "8679b7e94e378141",
"name": "tab away",
"style": {
"label": true
},
"nodes": [
"355204c71679f0b2",
"261ed7470526be54"
],
"x": 74,
"y": 479,
"w": 172,
"h": 122
},
{
"id": "355204c71679f0b2",
"type": "ui_button",
"z": "8679b7e94e378141",
"g": "6a07b007c072a673",
"name": "",
"group": "c3089136b03388ac",
"order": 3,
"width": 0,
"height": 0,
"passthru": false,
"label": "fantastic",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "",
"payload": "Fantastic",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 160,
"y": 520,
"wires": [
[
"0d2d2837d831c64d"
]
]
},
{
"id": "261ed7470526be54",
"type": "ui_button",
"z": "8679b7e94e378141",
"g": "6a07b007c072a673",
"name": "",
"group": "c3089136b03388ac",
"order": 3,
"width": 0,
"height": 0,
"passthru": false,
"label": "anything",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "",
"payload": "Anything",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 160,
"y": 560,
"wires": [
[
"0d2d2837d831c64d"
]
]
},
{
"id": "e5943e5df2fa3c2b",
"type": "group",
"z": "8679b7e94e378141",
"name": "tab home",
"style": {
"label": true
},
"nodes": [
"8e34ac5da484d19f",
"6a8ff6025084f6aa"
],
"x": 74,
"y": 339,
"w": 192,
"h": 122
},
{
"id": "8e34ac5da484d19f",
"type": "ui_button",
"z": "8679b7e94e378141",
"g": "e5943e5df2fa3c2b",
"name": "",
"group": "c86213fc1aa53032",
"order": 3,
"width": 0,
"height": 0,
"passthru": false,
"label": "interesting",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "",
"payload": "Interesting",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 170,
"y": 420,
"wires": [
[
"0d2d2837d831c64d"
]
]
},
{
"id": "6a8ff6025084f6aa",
"type": "ui_button",
"z": "8679b7e94e378141",
"g": "e5943e5df2fa3c2b",
"name": "",
"group": "c86213fc1aa53032",
"order": 3,
"width": 0,
"height": 0,
"passthru": false,
"label": "something",
"tooltip": "",
"color": "",
"bgcolor": "",
"icon": "",
"payload": "Something",
"payloadType": "str",
"topic": "topic",
"topicType": "msg",
"x": 170,
"y": 380,
"wires": [
[
"0d2d2837d831c64d"
]
]
},
{
"id": "c86213fc1aa53032",
"type": "ui_group",
"name": "Default",
"tab": "27e03abe3824c2f2",
"order": 1,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "c3089136b03388ac",
"type": "ui_group",
"name": "Default",
"tab": "539acf5aa46cc42a",
"order": 1,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "27e03abe3824c2f2",
"type": "ui_tab",
"name": "Home",
"icon": "dashboard",
"disabled": false,
"hidden": false
},
{
"id": "539acf5aa46cc42a",
"type": "ui_tab",
"name": "Away",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]