# Dynamically reading templates on a window

**URL:** <https://forum.inductiveautomation.com/t/dynamically-reading-templates-on-a-window/54509>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [December 29, 2021, 8:12am UTC](https://forum.inductiveautomation.com/t/dynamically-reading-templates-on-a-window/54509 "2021-12-29T08:12:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![szcz](https://avatars.discourse-cdn.com/v4/letter/s/ec9cab/32.png) [@szcz](https://forum.inductiveautomation.com/u/szcz)\
**Post date:** [December 29, 2021, 8:12am UTC](https://forum.inductiveautomation.com/t/dynamically-reading-templates-on-a-window/54509/1 "2021-12-29T08:12:24Z")

</div>

Hello dear Ignited,

I can’t wrap my head around yet simple concept. I have 30+ templates within a “bigger” template (that “bigger” template is then placed on a Main window). Inside this “bigger” template, there is also a button next to these 30+ other templates (these 30+ templates are of the same “class”).

My goal: to select all the templates from the “bigger” template and access their properties. Then, later, use it in a SQL query.

The relevant code for my attempt was as follows and this code is in a button on a template where these 30+ templates reside:

```auto
components = event.source.parent.getComponents()

for component in components:
	if 'Z' == component.name[0]: 
		var = str(component.name)
		print component.name, event.source.parent.getComponent(var).is_visible

```

And that gives me an error of “is\_visible not being property of an object”. is\_visible is a custom property of the inner template (These 30+ templates in a bigger one). However, if I use e.g. ‘Z12\_note’ string inside the getComponent() instead of var, I get what I desire (i.e. value of is\_visible for template in current iteration).

What am I missing here? Both var and ‘Z12\_note’ are of the same type - str.

Thank you very much for your advices and opinions.

Take care.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 29, 2021, 1:40pm UTC](https://forum.inductiveautomation.com/t/dynamically-reading-templates-on-a-window/54509/2 "2021-12-29T13:40:08Z")

</div>

Try using:

```auto
print component.name, component.getComponent(0).is_visible

```

Template instances are layered objects–the root container of an instance is not at the same level as the component in the outer container.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 29, 2021, 1:41pm UTC](https://forum.inductiveautomation.com/t/dynamically-reading-templates-on-a-window/54509/3 "2021-12-29T13:41:39Z")

</div>

Also explore with something like this:

```auto
print component.name, type(component.getComponent(0))

```

---

<div class="post-metadata">

**Author:** ![szcz](https://avatars.discourse-cdn.com/v4/letter/s/ec9cab/32.png) [@szcz](https://forum.inductiveautomation.com/u/szcz)\
**Post date:** [December 29, 2021, 2:13pm UTC](https://forum.inductiveautomation.com/t/dynamically-reading-templates-on-a-window/54509/4 "2021-12-29T14:13:18Z")

</div>

Greetings Mr. PTurmel,

Thanks for the feedback, what worked for me was

```auto
component.getComponent(0).getPropertyValue('is_visible')

```

type(component.getComponent(0)) has returned _‘com.inductiveautomation.factorypmi.application.components.template.VisionTemplate’_  
Nevertheless, your suggestions have brought me “over the finish line”

Thank you very much for the support.
