Let’s Build Something: Making Templates in the Vision Module2 minute read
A How-To Guide by Travis Cox
Templates are a simple but very powerful feature in Ignition’s Vision Module that you can use with your windows. The power comes from the ability to modify only the template in one location while affecting all of the instances used throughout the project.
I find that a lot of people get tripped up with how the layout works and what happens when you resize the template. Here are steps you can follow to make a successful template in the Vision Module. (Please note: the template process for Vision is markedly different from Perspective, which offers a different set of functionalities for creating templates.)
By default, when you drag a template onto the window from the Project Browser, the size of the instance is exactly the same size as the master template (template definition). You can make the size of the template instance on the window larger or smaller, but it only changes the size of that instance. Usually, people want to make the template instance larger than what was defined.
However, if you modify the size of the master template it will NOT automatically resize the template instance on the window. For that, you must locate the template instance (everywhere it is being used), right-click and select "Revert to Master Size."
That will change the size of the template instance on the window to the size of the master template.
Putting a template on the window is the same idea as putting a Vision component on the window. It is very important to note that you are now dealing with two different layouts: the layout of the template on the window AND the layout of the components inside of the template. By default, the layout of the template instance on the window will be "Relative - Maintain Aspect Ratio" and the layout of the components inside of the template is "Relative - Stretch."
The layout of the template instance dictates the layout of the components inside of the template. In other words, if the template instance does not resize, then the components inside of the template will also not resize. Additionally, the template instance can have a different layout than the components inside of the template. For example, you may want the template instance to fill out the entire window using an anchored layout, but you want the components inside of the template to maintain their aspect ratio.
That happens because a template acts in the same way a "Component Group" does by default. That means the layout is stuck to "Relative - Stretch." If you want the template instances to respect your layout settings, you need to set the "Enable Layout" property to “true” in the template definition.
That little checkbox will allow you to control the layout inside of the template. With that change, you can now control both layouts: on the window and in the template.