Read and write context variables in dashboard template script section

So I'm trying to read and write context variables like flow or global in the script section of a dashboard template node.
When trying to access the flow.get('x'); variable in a function, I get the console error that 'flow is not defined'. So I'm guessing that I'm in the wrong scope, I tried a lot but unfortunately I can't find the right one.

Welcome to the forum @Fliens

The context exists in the node-red server. The script in a ui-template node runs in the browser so does not have any access to the context.

But that can't be true.
I found this post where they are using the context variables in the template node.
There must be a way to access the variables so that I can also write to them. (Or I hope so)

That post is about the core template node (not the dashboard template node) and it is about inserting the current value of a context variables into the output at the time it renders the template.

As Colin said, you have no access to the context once any output is transferred to the browser.

The only way you can set a context variable from the Dashboard is if you implement a http endpoint or a websocket endpoint as part of your flow and either POST (or send to the WS) the value you want to change.

Or of course you include the value from context as a constant in the script that is sent to the dashboard. That won't work if the value changes after you send it to the dashboard.

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