How to use nested handlebars?

Hello,
I’m trying to use an array of strings in a workflow payload and use each element in the array to pull a tag with the same name from a device. I use a loop to loop through the array but I’m not sure how to use string manipulation to pull the device tag.

Here’s my payload in the tag loop.
image

And trying to pull the tag that is named {{working.tag_loop.value}}.
device.tags.{{working.tag_loop.value}}

The resultant field that gets populated is just a string that says “device.tags.***_alarm” instead of the tag object.

Hey @Zach_Jacobs,

Just so I have a better idea of what your issue is, you’re saying that {{working.tag_loop.value}}.device.tags.{{working.tag_loop.value}} is resulting in a string that says device.tags.***_alarm, right?

Please correct me if I’m wrong. I want to fully understand your issue so that I can help you as best I can.

Heath

That wasn’t formatted well on my end. I have a device tag named "foo_alarm" that I want to request the value of from a custom MQTT request. The way I do this is to send an array of tag names to a custom MQTT endpoint. I have tag names in an array: payload.tags. I use that as input to a loop with the loop variable being working.tag_loop. In the loop, I can reference an individual strings as {{working.tag_loop.value}}. This gives me a string of "foo_alarm". What I’m trying to do is to pull the actual value of that device tag.

Normally, I would just type {{device.tags.foo_alarm}} into the workflow to request the foo_alarm value but since I am receiving foo_alarm from a message I can’t type that in a head of time.

I tried this: device.tags.{{working.tag_loop.value}} but it just gets resolved into a "device.tags.foo_alarm" string on the payload instead of pulling the foo_alarm value. I tried to encapsulate the entire thing in a nested handlebar and that didn’t seem to work either {{device.tags.{{working.tag_loop.value}}}}

@Zach_Jacobs,

Thank you for all the clarifying information!

It looks like what you’re asking has been asked a few times. You can see those responses here and here.

I think what you might be looking for is Handlebar’s built-in lookup helper. It can be used to dynamically reference a key.

Let me know if you run into any other issues.

Thank you,
Heath

1 Like

@Heath FYI that the lookup helper link is broken.

@Wesley_Manning,

For your reference, the following link should work:

https://handlebarsjs.com/guide/builtin-helpers.html#lookup

Thanks
@Aidan_Zebertavage