Template flow context with variable names

Hello,

I’m using a mustache template node to populate a value from the flow context.

"{{{flow.config.name}}"

This works as expected.

However, when I store multiple objects within the flow context using a variable, is there a way of using that in the template node?

msg.contextName = "foo";
const contextName = msg.contextName;
msg.payload = {
   "name": "bar"
}
flow.set(`config.${contextName}`, msg.payload);
msg.contextName = "bar";
const contextName = msg.contextName;
msg.payload = {
   "name": "foo"
}
flow.set(`config.${contextName}`, msg.payload);

I now have two objects in my config flow context.

{{{flow.config.foo.name}}
{{{flow.config.bar.name}}

I can use a change or function node to set these values before the template node. Ideally, it would be nice to use directly within the template,

I have tried the following without success.

{{{`flow.config.${msg.contextName}.tenantname`}}}
{{{`flow.config.${contextName}.tenantname`}}}
{{{flow.config[contextName]tenantname}}}

Thanks in advance.
Harry

Just use a change node to set msg.config to flow.msGraphQLConfig then you can access {{{msg.config.tenantname}}} and {{{msg.config.foo.name}}} and {{{msg.config.bar.name}}} in the template.

Alternatively, if it is the dynamic aspect you are trying to achieve, then use [] square bracket notation in a change node before hand. e.g. set msg.whatever to flow.config[msg.contextName] then use {{{whatever}}} in the template.

Thanks for the quick response, I stated, I can use a change or function node, ideally looking to see if it can be done with just a tenmplate node

No, mustache is "logic-less"

1 Like