# Is there a way to see if a template exists in the vision client?

**URL:** <https://forum.inductiveautomation.com/t/is-there-a-way-to-see-if-a-template-exists-in-the-vision-client/41988>\
**Category:** Ignition\
**Tags:** vision, ignition80\
**Created:** [January 6, 2021, 3:29am UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-see-if-a-template-exists-in-the-vision-client/41988 "2021-01-06T03:29:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaveRNeal](https://avatars.discourse-cdn.com/v4/letter/d/53a042/32.png) [@DaveRNeal](https://forum.inductiveautomation.com/u/DaveRNeal)\
**Post date:** [January 6, 2021, 3:29am UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-see-if-a-template-exists-in-the-vision-client/41988/1 "2021-01-06T03:29:27Z")

</div>

Good Evening,

I’m working in Ignition 8.0 and attempting to use a dynamic binding on a template path. What I’d like to do is fall back to a default template if the dynamic one does not exist. Is there a decent way to do this in 8.0? I’ve found [this link](http://forum.inductiveautomation.com/t/check-to-see-if-template-path-exists/25081) but that solution seems to only apply to version 7.9 and earlier. Should I be using [system.gui.getQuality()](https://docs.inductiveautomation.com/display/DOC80/system.gui.getQuality)? If so what propertyName should I check to see if the template exists?

---

<div class="post-metadata">

**Author:** ![chasondeshotel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chasondeshotel/32/20032_2.png) [@chasondeshotel](https://forum.inductiveautomation.com/u/chasondeshotel)\
**Post date:** [January 6, 2021, 6:36am UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-see-if-a-template-exists-in-the-vision-client/41988/2 "2021-01-06T06:36:35Z")

</div>

imo the best improvement of 8.0 is that resources are flat text files so I’d imagine you could do something like

```auto
def template_or_default(template_name):
    import os.path
    # or whatever the actual file location is
    template_path = 'install_dir\data\projects\project_name\resources\' + template_name + '.json'
    return template_name if os.path.isfile(template_path) else 'default_name'

template_or_default('foo')

```

I don’t have an Ignition instance handy to test right now so ymmv

---

<div class="post-metadata">

**Author:** ![kcollins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kcollins/32/19646_2.png) [@kcollins](https://forum.inductiveautomation.com/u/kcollins)\
**Post date:** [January 6, 2021, 3:30pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-see-if-a-template-exists-in-the-vision-client/41988/3 "2021-01-06T15:30:05Z")

</div>

You might have some success looking at the `.loadedTemplate` property of the template component. You could pivot off of that when it goes to `None`. Here is a visual example:

 ![Loaded Template Example](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/5/5554ebf4f3f6088fdb592c03c7a048a4139b84e3.gif)

Note that, with this reactive approach, you will produce a warning in the log when the template component attempts to load a missing template. Unfortunately, there isn’t an equivalent for templates to [`system.gui.getWindowNames()`](https://docs.inductiveautomation.com/display/DOC81/system.gui.getWindowNames) that would allow you to proactively (in an easy manner) determine whether the loading of a given template will succeed.

---

<div class="post-metadata">

**Author:** ![chasondeshotel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chasondeshotel/32/20032_2.png) [@chasondeshotel](https://forum.inductiveautomation.com/u/chasondeshotel)\
**Post date:** [January 6, 2021, 6:15pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-see-if-a-template-exists-in-the-vision-client/41988/4 "2021-01-06T18:15:33Z")

</div>

> Note that, with this reactive approach, you will produce a warning in the log when the template component attempts to load a missing template.

That's easy to fix--wrap the call to `.loadedTemplate` in `eval()`

```auto
component = event.source.parent.getComponent('foo')
component.templatePath = 'foo'

# returns None or the name of the template
print eval("component.loadedTemplate")

```

That's a more elegant and portable solution than reading the filesystem but is there a way to hide the ugly "template doesn't exist" box? (edit: I know we'd be quickly defaulting to another template but I'd be surprised if it didn't flash)

---

<div class="post-metadata">

**Author:** ![kcollins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kcollins/32/19646_2.png) [@kcollins](https://forum.inductiveautomation.com/u/kcollins)\
**Post date:** [January 6, 2021, 6:55pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-see-if-a-template-exists-in-the-vision-client/41988/5 "2021-01-06T18:55:41Z")

</div>

It isn’t the reference to `.loadedTemplate` that is broken and causing the warning, but that the loaded template is invalid (and thus legitimately `None`); the use of eval is unneeded. EDIT: In other words, setting the `templatePath` to something invalid is what actually generates the warning.

---

<div class="post-metadata">

**Author:** ![DaveRNeal](https://avatars.discourse-cdn.com/v4/letter/d/53a042/32.png) [@DaveRNeal](https://forum.inductiveautomation.com/u/DaveRNeal)\
**Post date:** [January 6, 2021, 7:17pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-see-if-a-template-exists-in-the-vision-client/41988/6 "2021-01-06T19:17:44Z")

</div>

Thanks so much for the help, you two! I ended up going with the .loadedTemplate route. I’ve got a fallback/default template hidden behind the dynamically loaded one, then use a simple runScript expression on the dynamic template’s visibility, setting the visibility bound to:

```auto
!isNull(runscript('self.loadedTemplate', 1))

```

---

<div class="post-metadata">

**Author:** ![chasondeshotel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chasondeshotel/32/20032_2.png) [@chasondeshotel](https://forum.inductiveautomation.com/u/chasondeshotel)\
**Post date:** [January 6, 2021, 7:35pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-see-if-a-template-exists-in-the-vision-client/41988/7 "2021-01-06T19:35:28Z")

</div>

Yeah, you’re right. I was looking at the log wrong.

So `Vision.Components.TemplateHolder` is actually generating the error, so you’d have to load it from that end to catch that warning

The implementation of `.getResourcesOfType` changed. This works for me on 8.0.16

```auto
def template_exists(template_name):
	"""
	Syntax: template_exists(template_name)

	Parameter:
	template_name: A string of the template's name. If in a directory prefix with the directory name: path/to/template

	Return Type: This method returns a Boolean value of class bool. This method returns True if the template exists otherwise returns False. 
	"""
	from com.inductiveautomation.factorypmi.application.model import TemplateManager
	
	context = event.source.getAppContext()
	project = context.getProject()
	resources = project.getResourcesOfType(TemplateManager(context).RESOURCE_TYPE)
	paths = [str(resource.getResourcePath()) for resource in resources]
	
	if 'com.inductiveautomation.vision/templates/' + template_name in paths:
		return True
	return False

print template_exists('foo')

```

---

<div class="post-metadata">

**Author:** ![chasondeshotel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chasondeshotel/32/20032_2.png) [@chasondeshotel](https://forum.inductiveautomation.com/u/chasondeshotel)\
**Post date:** [January 6, 2021, 7:54pm UTC](https://forum.inductiveautomation.com/t/is-there-a-way-to-see-if-a-template-exists-in-the-vision-client/41988/8 "2021-01-06T19:54:12Z")

</div>

That’s a nice, concise solution @DaveRNeal. If you don’t see the bad template overlay then I think that’s definitely the way to go
