Apply Template
Last updated
Last updated
Let's understand how to apply the created template in dynamic and custom models with the help of examples.
When a dynamic model or dynamic children are created, all the nodes (except the top node) are disabled from editing and they simply just add up over each level.
Now, with the help of a template, you can modify the existing node structure while retaining its dynamic nature. There are two ways by which you can modify the model with templates:
By replacing the existing node structure (or)
By inserting new nodes within the structure
To do this, click the Apply Template button from the Templates window.
It has two options - Replace Nodes with Template and Insert New Nodes with Template.
In this case, the template is applied to multiple nodes wherever required to replace their original structure with the template structure.
Let us see the steps to replace the dynamic nodes using template.
Create the template structure as needed.
Click Apply Template-> Replace Nodes with Template button.
Datasource Node Editor opens in which you can configure the template rules.
a) Select Datasource Node: Select the datasource node under which you want to apply the template.
b) Select Level: Select the level at which you want to replace the existing nodes with the template. In the below image, parent of the leaf nodes are chosen to be replaced with template.
ValQ automatically detects which level is to be replaced by the template. Only the last two levels in the model (leaf nodes and parent of leaf nodes) are available for replacing nodes with template.
If leaf nodes are chosen as template keys, then select the level that is the parent of leaf nodes.
Template Rules
c) Select Template: This displays the current template. You can also choose any other template you had created, from the dropdown (if any) to apply that.
d) Apply to: In this section, choose All Nodes to apply the template to all the nodes at the selected level (or) you can choose Filter to apply the template to only a few specific nodes at the level based on certain filter conditions.
e) Append Template Root Node Name: Checking the Append Template Root Node Name option appends the template name with the name of the root node.
E.g. 'Men' node is renamed to 'Men - Net Profit' if the 'Net Profit' template replaces the Men node structure.
Click Preview to view the changes and then click Save to apply the template.
In the below example which has a dynamic model, we'll see how net profit is calculated for the regions - Asia and US.
Step 1: Find below the example of a dynamic model. Click Templates.
Step 2: The template is created first with the desired structure and configuration along with the template key nodes as shown below.
Step 3: Click Apply Template->Replace Nodes with Template.
Step 4: The level and the template are selected. Then the template is applied to replace all the nodes at the Region level. Click Preview.
Step 5: After previewing, click Save to apply the template.
Template is applied to the dynamic model as shown below. Nodes that belong to a particular template share the same color scheme.
This way each region's profit is calculated and since the model is still dynamic any new region that gets introduced will automatically take the shape of the template structure as we have applied the template to all nodes at the Region level.
In this example, two templates have been applied to the dynamic model at the Company level. The nodes Company A and Company B have been replaced with Template (1) and Company C and Company D with Template (2).
This is achieved by using the Add Rule and then the Filter option in the Apply to section where two rules are added, one for each template.
Click Preview to verify and then click Save.
The templated nodes in the model are color-coded to identify the different templates that have been applied.
The other way of applying a template is to insert the template nodes as new nodes at the selected levels in a dynamic structure. The new nodes can be added as children of all the parent nodes in a level or only to a few parent nodes in a level using the Filter option.
Let us see the steps to insert the template in the model as custom new nodes.
Create the template structure as needed.
Click Apply Template->Insert New Nodes with Template button.
Datasource Node Editor opens in which you can configure the template rules.
a) Select Datasource Node: Select the Data Source node under which you want to apply the template.
Template Rules
b) Select Template: This displays the current template. You can also choose any other template you had created, from the dropdown (if any) to apply that.
c) Parent Level: Select the parent level under which you want to insert the template nodes as children.
Unlike the Replace option, which only allows you to replace leaf nodes and parent of leaf nodes, inserting can happen at any category level.
d) Apply to: In this section, choose All Nodes to insert the template under all the parent nodes at the selected level or use Filter to insert under only specific parent nodes at the selected level based on filter conditions.
In the below example, we have created a template structure for Net Profit with Discount% and applied it using the Insert with template option for All Nodes under Product level.
This will add the template as additional nodes under every Product parent (every Men and Women).
In this example, Template (1) has been created with few formula nodes to calculate the variance.
This will be applied only for Supplier A in India region for Apple product. These specific categories are filtered using the Filter option in Template Rules as shown in the image below.
And is the operator type used in the example to combine the filtering rules which means all the categories matching the entered text should be filtered.
On applying this template to the model, the variance template structure gets added as a descendant of the filtered parent node (Apple node belonging to Supplier A of India).
To apply the template, the Data source node editor can also be opened by clicking on the below icons.
In a custom model (editable model) we can add new nodes in the form of template nodes just like adding any other node in the model. Here the template is added for a single node at a time. Let us see the steps now.
Create the template structure as needed.
In the model, select the node where you want to add the template.
Click Add New Node -> Add Node using Template.
Choose the template you want to add and select the source key to fetch the values for template key nodes.
Clicking on Select source key opens a pop-up where you can select the source key for template.
Choose the source key from the list and the position of the template to be added as a child or sibling of the selected node.
Click Preview to view the changes and then click Apply to apply the template.
The nodes are added as template as shown in the below image.
Note:
Add node using template is also available for dynamic model and dynamic children. However, using this option will add the template outside of dynamic node structure as a new branch to the model.