# Template Binding

**URL:** <https://forum.inductiveautomation.com/t/template-binding/10343>\
**Category:** Ignition\
**Created:** [August 14, 2015, 4:08am UTC](https://forum.inductiveautomation.com/t/template-binding/10343 "2015-08-14T04:08:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DavidWisely](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/davidwisely/32/10482_2.png) [@DavidWisely](https://forum.inductiveautomation.com/u/DavidWisely)\
**Post date:** [August 14, 2015, 4:08am UTC](https://forum.inductiveautomation.com/t/template-binding/10343/1 "2015-08-14T04:08:03Z")

</div>

I’m using a Template Canvas.  
The Template Canvas has a Custom Property ‘PropX’.  
The Template Canvas is dynamically populated with templates using a script.  
The Template has a Custom Internal Property ‘PropY’.

I would like to bi-directionally bind ‘PropY’ to ‘PropX’.

The idea is that when I update ‘PropX’ on the Canvas, all the templates are updated, and when I click on one of the templates to update it’s PropY, it also updates all other templates.

I can do this using a Client Tag, but I would like to have the Template Canvas ‘self contained’ so that it can easily be used in multiple locations.

I’ve tried using an indirect tag on the template like this:  
‘{1}.parent.parent.parent.parent.PropY’ where {1} = Template.Name  
This format works in a script when updating the Canvas from the Template, but not for an Indirect Tag.

Any help appreciated.

---

<div class="post-metadata">

**Author:** ![DavidWisely](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/davidwisely/32/10482_2.png) [@DavidWisely](https://forum.inductiveautomation.com/u/DavidWisely)\
**Post date:** [August 18, 2015, 10:54am UTC](https://forum.inductiveautomation.com/t/template-binding/10343/2 "2015-08-18T10:54:30Z")

</div>

Anybody got any ideas on this one?  
Do you need more information?

---

<div class="post-metadata">

**Author:** ![DavidWisely](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/davidwisely/32/10482_2.png) [@DavidWisely](https://forum.inductiveautomation.com/u/DavidWisely)\
**Post date:** [August 20, 2015, 6:56am UTC](https://forum.inductiveautomation.com/t/template-binding/10343/3 "2015-08-20T06:56:46Z")

</div>

Ok, I’ve managed to do it in a script that I’ll use for now, but it’s a bit messy so if there’s a better way, please let me know.

I’ve added a custom method to the ‘Template Canvas’ that will update all templates within the Canvas called ‘UpdateComponents’.  
This is triggered from the canvas properytChange event when the selected property is changed.

```auto
def UpdateComponents(self, templateName, propertyName, newValue):
	"""
	Update the property of all templates of the same type within the Template Canvas with a new value 
	
	Arguments:
		self: A reference to the component instance this method is invoked on. This argument
		  is automatic and should not be specified when invoking this method.
		templateName: The name of the template within the Template Canvas to update
		propertyName: the property of the template to change
		newValue: the value to set the property to
	"""

	# Drill down to where the templates are	
	children = self.getComponents()
	if len(children) > 0:
		for item in children:
			className = str(item.getClass()) 
			if className.endswith("TemplateCanvas$1'>"):
				itemChildren = item.getComponents()
				if len(itemChildren) > 0:
					for temp in itemChildren:
						className = str(temp.getClass()) 
						if className.endswith("JViewport'>"):
							tempChildren = temp.getComponents()
							if len(tempChildren) > 0:
								for temp1 in tempChildren:
									className = str(temp1.getClass()) 
									if className.endswith("LayoutPanel'>"):
										temp1Children = temp1.getComponents()
										if len(temp1Children) > 0:
											
											# iterate throught all the Templates in the Template Canvas
											for temp2 in temp1Children:
												if temp2.name == templateName:
													# this is the specified template,
													# set the new property value
													temp2.setPropertyValue(propertyName, newValue)
```
