Default Image block fallback

Hi there,

I was wondering if there was a way to render a fallback image for a dashboard. Basically, my use case is that I’d like to display an image of the sensor provided by the customer. If no image exists, then I’d display a “No Image Available” image (as opposed to a block render error).

One idea I had was to add a tag to the devices that specified the path to the image. I could then set this imagePath to the fallback image if none other existed. However, I don’t think I can use a context variable to pass this down as the user would have to pass the path in – ideally I just want to use the value of this tag depending on the image selected. Any thoughts? Thanks!

I think what you are looking for is the {{defaultTo}} helper.

If you are storing the URLs on a device tag called “imageUrl”, you could reference that value through a device context variable (called “deviceId” in this example):

{{ctx.deviceId.tags.imageUrl}}

Then, fall back to a default image of your choice if that value is not set:

{{defaultTo ctx.deviceId.tags.imageUrl 'https://placekitten.com/640/640'}}
1 Like