Search

User Manual

GETTING STARTED


MODULES AND PLATFORM


APPENDIX


TUTORIALS & HELPFUL TRICKS


GLOSSARY


STRATEGIC PARTNER LINKS

Sepasoft - MES Modules
Cirrus Link - MQTT Modules

RESOURCES

Inductive University
Ignition Demo Project
Knowledge Base Articles
Forum
IA Support
SDK Documentation
SDK Examples

ALL USER MANUAL VERSIONS

Ignition 8.1
Ignition 7.9
Ignition 7.8

Deprecated Pages

Skip to end of metadata
Go to start of metadata


The Template Canvas component works much like the Template Repeater in that it can easily create multiple copies of a master template. What makes the Template Canvas unique is that it can display instances of multiple master templates, and set their layout in any way you want. The Template Canvas has a customizer that can help put the templates together within it, but the customizer is just driven by a Templates dataset property on the Template Canvas. The Template Canvas can be made dynamic by setting up a binding on the Templates property, such as a query that pulls in an entirely new dataset of information, or even a cell update binding, which updates individual cells of the dataset. With that, you can load new templates into the canvas at runtime, or even move the templates around.

The Template Canvas has two layout systems: Absolute Positioning, where each template instance has an absolute position within the Template Canvas, and Layout Positioning, which uses the MiG Layout system to place the instances within a grid like system.

Creating a Template

Before we get started with the Template Canvas, we first need to have a template. Here we are going to make a simple Form Input template, that consists of a Label and a Text Field. The template will need two parameters. A Label_Text parameter which is what will get displayed in the label, and a TextField_Text which we can use to pass user input outside of the template by making it bidirectional. This template is a great way of quickly making user input forms, by using a template for each piece of info that needs to be collected. The steps for making the template are listed below, or you can skip ahead to using the Template Repeater in the next section.

On this page ...


IULocgo


Template Canvas

 Making the Template
  1. In the Templates section of our Project Browser, create a new template called Form Input. We are going to want to pass in values to and from the template, so we need to create Template Parameters.
  2. Right click in the Form Template workspace, and select Customizers > Custom Properties. Add a Template Parameter called Label_Text, and make it a String type.
  3. Add a second Template Parameter called TextField_Text, and make it a String type, and click OK to save your template parameters.
  4. Next, drag a Text Field component and a Label component onto the Template.
  5. On the Label component, set the Horizontal Alignment property to Trailing.



  6. Finally, we want to setup some bindings on our Template.
    1. Using a property binding, bind the Text property of the Label component to the Label_Text Template Parameter.
    2. Using a property binding, bind the Text property of the Text Field component to the TextField_Text Template Parameter, and make it Bidirectional.




  7. Set the Size and Position for the components by right clicking on each componet inside to 20 pixels.  Next, set the height for the Form Input template as shown in the image below. 
    Note, make sure to drag your two components to the top of the template before adjusting the size.



  8. The template is now finished and ready to use. See the image below. Yours should look similar. Note the two Template Parameters, as well as the placement of the components.
  9. Once you have the properties added and components bound, type a value into each Template Parameter so we can easily tell that our bindings are working.
    1. Label_Text: Label
    2. TextField_Text: Text




Absolute Positioning

First, we can set up our Template Canvas using Absolute Positioning, which is a little simpler to understand as each template has a width and height as well as an x and y position. 

  1. Drag a Template Canvas component to a window and open the Template Canvas Customizer. The customizer provides an easy interface to setting up our templates.



  2. Enter in the following values for the first instance:
    1. Name: First Name
    2. Template: Form Input
    3. Absolute Positioning: 0, 0, 200, 20
    4. Parameters: Label_Text = First Name (leave TextField_Text blank)

  3. Click the Add button to add the instance. The instance will then be visible in the preview section of the window. Note that values for the components are still using the default values for the Label_Text and TextField_Text. This is intentional. The new values will appear once you hit OK and close the canvas customizer.

    The following feature is new in Ignition version 8.0.6
    Click here to check out the other new features

    Labels were added to the Absolute Positioning properties: X, Y, width, and height labels. A Z-index field was added indicating where a given template instance should appear in the z-order within the template canvas (top or bottom).


    Take note of the yellow outline around the instance in the image, and how First Name is highlighted at the top of the customizer. This means that the instance is selected, and the customizer is in edit mode. This allows you to make changes to the selected instance. To exit edit mode and add a new instance, click on the Cancel button in the lower left of the window. Clicking on the Cancel button in the lower right will cancel out of the customizer.


  4. Let's add another instance. Click on the plus  icon in the Instance area to clear the Add/Edit Instance fields from the prior entry, and enter the following: 
    1. Name: Last Name
    2. Template: Form Input
    3. Absolute Positioning: 0, 20, 200, 20
    4. Parameters: Label_Text = Last Name (leave TextField_Text blank)

  5. Once entered, click the Add button again. You'll see that you have two instances visible in the preview section of the window. Once both instances are configured, click the OK button. 

  6. Now you will see both instances appear in the Template Canvas. 




  7. If a new instance needs to be added, it can be added through the Template Canvas Customizer. However, the Template Canvas also has a 'Templates' property. This property stores all of the data that was entered into the customizer into a dataset, so new instances can be configured directly on the Templates property. View the dataset by clicking the Dataset Viewer button next to the Templates property. Furthermore, template instance configurations could be stored in a database table, and the Template Canvas could fetch the data with a SQL Query binding on the Templates property.




Layout Positioning (MiG Layout)

Instead of having to manually enter a size and position for each instance, we can make use of Layout Positioning to have the Template Canvas determine the best position for each instance, while also making suggestions as to where each instance is placed in relation to another. The layout positioning uses a grid-methodology to instance placement. Each instance, unless otherwise specified, is considered a single "cell" in the grid.

Don't Mix Absolute and Layout Positioning

We recommend not using both Absolute and Layout Positioning for instances on the same Template Canvas. Select either Absolute or Layout Positioning for your instances. Layout Positioning will determine the best position for each instance in your canvas, where Absolute Positioning allows you to manually specify the width, height, x and y positions for each instance.

Continuing from the example above, the First Name and Last Name instances are using Absolute Positioning. Let's tell the First Name instance to use Layout Positioning and enter the 'wrap' parameter. This means the next cell in the grid should be placed on the next row. 

  1. With the Template Canvas component selected, open the the Template Canvas Customizer again, and make the following modification to the First Name instance.
    1. Click the radio button for the Layout Positioning property and enter 'wrap' the field.
  2. Click Apply, and the First Name instance will appear to overlap with the Last Name instance. This is because the grid only accounts for instances using the Layout Positioning. 

  3. Next, we can configure the Last Name with Layout Positioning as well. Make the following changes to the Last Name.
    1. Click Layout Positioning radio button and enter 'wrap' in the field below.

  4. Once the changes have been applied, click OK. You'll notice in the preview section of the window that both instances are now in line. 

  5. Open the Templates property by checking the Dataset View button. Notice that the x, y, width, and height columns are no longer used, but the layout columns for First Name and Last Name now have a value of 'wrap'.



  6. Like the previous example, new rows can be added directly to this dataset. Furthermore, the 'wrap' value means the next template instance will begin on a new line. Add three new instances for Street Address, City and Account Name. Use either the Template Canvas Customizer or simply add two new rows in the dataset viewer with the values shown in the image below. 




Read User Input

The last step is to read the user input. Put the Designer into Preview Mode and add some values for each text field component. Once finished, switch the Designer back to Design Mode, and add a Button component to the window (not the template canvas)

Add a script to the Button component using the Code Snippet below - Read User Input Example. Place the code on the actionPerformed event of your component by double clicking on the Button component and opening the Script Editor tab.

# Reference the template canvas component, and call the getAllTemplates() method.
# This will return a list of every instance in the canvas
templateList = event.source.parent.getComponent('Template Canvas').getAllTemplates()
 
# Initialize a list. User input from each text field will be stored in this variable
userInput = []
 
# Iterate through each template instance inside the canvas
for template in templateList:
     
    # add the user inputted value to the userInput list. The values are originally returned in Unicode.
    # the Python str() function is casting the Unicode values as string values.
    userInput.append(str(template.TextField_Text))
     
# Show the values in a messageBox. This could be replaced with an INSERT query, or some other action.
# str() is used again to case the list as a string. This only required to work with the messageBox function
# since the function requires a string argument be passed in
system.gui.messageBox(str(userInput))

When running the script, each value should appear in the message box. If you're not getting a value in the message box, make sure the Text Field property is bound to the TextField_Text template parameter as mentioned in the Creating a Template section, Step 6b.

This example can easily be expanded to do something more meaningful with the input, like store to a database table.





  • No labels