This lesson is part of the Vision Components and Property Bindings course. You can browse the rest of the lessons below.

LESSON LIST

Autoplay Off
Take topic challenge

Supplemental Videos

Description

The Template Repeater repeats instances of templates any number of times. It can arrange them vertically, horizontally, or in a "flow" layout, which can either be top-to-bottom or left-to-right. If there are too many to fit, a scrollbar is displayed.

Video recorded using: Ignition 8.1

Transcript

(open in window)

[00:00] In this video, we're going to take a look at the template repeater component. The template repeater is a powerful component that allows us to quickly and easily repeat a template multiple times on a window. I'll go ahead and add a template repeater component to the window. And as I expand it, you'll notice that it actually starts out blank. To use the template repeater component, we first need to set a few properties. We'll start with the template path property, where we need to select a template that we want to repeat within this component. I'll go ahead and click on the dropdown here, and select my motor template that I made earlier in the templates indirect bindings video. The next property that we need to configure is the repeat behavior property, which by default is set to count. While set to count, the behavior of the template repeater is that it will repeat the template the number of times specified in the repeat count property.

[01:07] So if I set this repeat count property to five, it repeats my template five times. It may look a little stretch now, but if I put my designer into preview mode and scroll down with the scroll bar, we can see that indeed there are five instances of the template within the template repeater component. Now, rather than having the template instances inside the repeater be all stretched out like they are right now, if we scroll down in the property editor for the template repeater, you'll notice there is a layout style property which by default is set to vertical. The vertical layout style will stretch the template instances horizontally, and then repeat them in a vertical line. There are a few different options that we can choose from including horizontal, which does sort of the opposite, stretches them vertically and repeats them in a horizontal line, flow, which will allow them to flow with their natural size that you created the template in, and best fit, which will fit the template instances within the bounds of the template repeater component as best it can.

[02:14] I typically like to use flow because it keeps the original size of my template intact, and then repeats it as many times as necessary. If I had too many instances to display or the template repeater was not large enough, then flow mode will offer a scroll bar in those cases. Now, if we take a look at the instances of the motor that are being repeated within the template repeater component, you'll notice they're all looking at motor one because that's the default value of my parameter motor number within my template. Now, it is possible to pass a parameter value into a template using the template repeater. While the repeat behavior is set to count, it's only possible to pass in a single parameter value into the template instances. And it's based off of the index parameter name property. This property needs to be set to the name of the parameter within your template.

[03:06] So in my case, the name of my parameter is motor number. So if I set this property to motor number, you'll see that I actually get some different instances of my motor within the template repeater. Now, you may notice that one of my motors here isn't quite working, motor zero. You'll notice if we look at my motor tags, I actually don't have a motor zero. And so this motor is not finding the corresponding tags to show any values. Now, the reason why I have a motor zero being displayed in my template repeater is because in repeat behavior of count, when we pass a parameter in, we always start with a parameter value of zero and go up to one less than your repeat count. So because I have a repeat count of five, I actually pass in a value of zero through four respectively, into the motor number parameter in my template.

[04:06] Because I don't have a motor zero, this isn't ideal. But luckily for us, there is another way that the template repeater repeats templates and passes in parameters. If we go back into our property list and change that repeat behavior property to dataset instead, you'll first notice that all of our template instances disappear. This is because the instances within the template repeater are no longer based off of the repeat count property. So even though this was set to five, it's not going to display five templates anymore. Instead, the template repeater's behavior is based off of the template parameters property. Now, you'll notice the template parameters property is a dataset. Let's go ahead and open up our dataset viewer. We currently have no rows or columns. The way this dataset works is that new column that we add needs to correspond to one of the parameters within our template.

[05:05] So if we have three parameters that the template is expecting, then we would add three columns here. Each column needs to have the same name as the name of the parameter within the template, and it needs to be the same data type. Now, since my template only has one parameter, I'm only going to need one column. So I'll go ahead and add a new column. Again, it needs to have the same name, so I'll call it motor number, and I'll select a data type of integer before adding that column. Each row corresponds to an instance of the template that will get displayed within the template repeater. So if I add three rows here and hit okay, I get three instances of the template displayed within the repeater. Going back into the dataset for template parameters, each value in the row, also corresponds to the parameter value that gets passed into the template.

[06:04] So if I have values here of two, three and six, and hit okay, you'll notice that now these instances are looking at motors two, three, and six. So if we wanted to display more template instances within our repeater, within the repeat behavior of dataset, all we need to do is go back into that dataset and add some new rows and give them some values. One, we'll say four and eight. Now, there's something important to remember when you pass parameter values in using a template repeater, and it's that the template repeater will really only work with templates that use standard types of parameters. So regardless of what repeat behavior you use on your template repeater, you cannot use a UDT data type on your template. So with most templates, template repeaters can be a great way to really easily display a lot of instances of a template on a screen very quickly.

You are editing this transcript.

Make any corrections to improve this transcript. We'll review any changes before posting them.