Turning an item on and off with a template widget

Hi,

I am trying to turn an item on and off in OpenHab via a template widget in HabPanel.
The reason I want to use a template widget instead of the normal switch widget is that I want the image on the widget to change depending on whether the item is on or off, and I also want the image to extend fully to the edges of the widget.

The code below works partially. The image changes depending on whether the item is on or off, but it is not possible to turn the item on and off using the widget.
Can anyone figure out why?

What code, there is nothing in your post…

’m trying to add it as an image instead. the code got deleted