Dynamic binding tag to template custom property

I'd like to be able to dynamically bind a tag to a custom property in a template so it can be accessed from a script within that template. The dynamically created tag change event directly executing a script within a template would be fine, too. Basically I have a bunch of conveyor shape templates (straight, 90 degree curve, 45 degree curve, etc) that all use the same color animation. I'd like to not have to maintain that same color animation script separately for each shape template, so I want to pull it out to a single script I can reference in all my templates via nested templates or otherwise. The current logic is below.

case(tag("[default]"+ {MDRZoneSingulate.panelName} + "/"+ {MDRZoneSingulate.conveyorName} + "_Status"),0,"Gray",1,"green",2,"red",3,"Yellow",4,"blue",5,"Gray","purple")

Thanks,
Michael

Make a custom property on the template for only the tag value, and then indirectly bind that to your target tag. Then, in another custom property, have your case statement inspect the value of the custom property that has the tag value. Pass the panel name and conveyor name into the template and use them for the indirect binding. Man its a friday. :upside_down_face:

In a second property's binding, use an expression that uses lookup to look at a global dataset tag that has the colors/status numbers defined. Something along the lines of:

lookup(
	{path.to.global.colors.tag},
	{this.custom.conveyorStatus},
	"black",
	"Status",
	"Color"
)

If you need to update colors, just adjust that global dataset.

Browsing the manual might help.

That's what internal template properties are intended for. Template properties themselves are expected to be supplied by the containing component. Internal properties are where you can create and bind subexpressions for the template's internal use. (And have property change event functionality.)

Figured out that you can only bind to internal properties which defeats what I was trying to do. I like the lookup to the dataset for this particular case, but would really like to be able to call something like a function to handle future use cases. Just getting my arms wrapped around Ignition and I feel like I'm typing with my elbows. Off to try to find function calls/definitions or something in the manual.

Thanks for the help!

Where are you supposed to put code that you want to use in multiple templates?

In the project script library.

IMNSHO, every event and component method should be a one-line statement delegating to a function in a project script.