Pack Transform Generating Templates

Parent Previous Next


Pack Data Transform Generating Templates


The Pack Data Transform uses dotliquid as the templating engine which can be confusing for some users. The purpose of this page is to help users understand how the syntax is used within the component. This should also help users learn how to use the pre-configured templates as well as create their own within the component.


First, it is important that users understand you can create any delimited, Xml, or Json formatted template. To quickly generate one based on the input(s), simply click the "Generate Template" hyperlink and the Template window will populate based on the selected format and input(s). Columns can also be added manually by dragging from the Input Definitions window and dropping to the Template window.


Syntax

Data replacements are in the format of {{inputname.columnname}} Example: Everywhere the user sees {{Input.SalesOrderID}}, it will be replaced with the row data for SalesOrderID. It is further broken down as follows:

Input = the name of the input on the left side of the UI (the top node of the Input Definitions window.)

SalesOrderID = column name from that input


As you can see in the example below, the SalesOrderID input on the left corresponds to the {{Input.SalesOrderID}} in the XML on the right:



Adding If statements

If conditional statements act the same as other languages (except uses the dotliquid syntax.) Users can add If statements by contributing the following:


{% if forloop.index > 1%},{% endif %}


Example:

{% if row1.CarID == 123 %} Write any text here {% endif %}


This will read "If CarID in row1 is equal to 123, then "Write any text here" will be added to the output. See the table below:


CarID

Info

123

Write any text here

456

Data

789

Data


As you can see, the Info column added "Write any text here" because it matched the condition that CarID = 123.


Important note: Spaces must surround equality/inequality operators used in If statements.


Comments

Comments can be added between objects Simply use the following tags:

{% comment %} {% endcomment %}


Example:
{{input.SalesOrderID}}{% comment %} add comma between objects - this comment tag can be removed from template {% endcomment %}



Loops

Loops can only be used with more than one input. In some cases, users may have to loop through more than one row that shares the same ID. To use loops in the Pack Transform, add the following:


{% for row1 in input1.Rows -%}


Row1 is the name of the loop iterator and is used to access any data from the rows in input1


Example:        

<CarID>{{ row1.CarID }}</CarID>

<CarName>{{ row1.CarName }}</CarName>

{% endfor -%}


Using more than one input with a parent – child relationship

The tables below will be used to establish the parent-child relationship


Parent Input has a single row with two fields. The parent is named "Input" (seen in the Input Definitions window)


OwnerID

Name

1

Jane Fields


Child input has two rows with two fields. The child is named "Input1" (seen in the Input Definitions window)

OwnerID

CarID

CarName

1

1

Maxima

1

2

Explorer


There is a relationship defined between the two inputs on OwnerID from Input and Input1


Users can use the generate template once the relationship has been defined.


When using multiple inputs, a relationship between the two is needed in the relationship tab.To add this relationship, perform the following steps:

1.Click the Relationships tab

2.Select the Parent Input in the first select box.

3.Select the Child Input in the second select box

4.Drag the parent column key to the child column key that links the tables

5.Click Update Mapping button

6.(Optional) Return to the Template tab and click the Generate Template hyperlink to auto-generate your template



Example:

We want to output an xml template defined as

<Owner>

<OwnerName>{{ input.Name }}</OwnerName>

<OwnerID>{{input.ID }}</OwnerID>

<Cars>

{% for row1 in input1.Rows -%}

       <CarID>{{ row1.CarID }}</CarID>

       <CarName>{{ row1.CarName }}</CarName>

{% endfor -%}

</Cars>

</Owner>

In this example, row1 is the name of the loop iterator and is used to access any data from the rows in input1.


Note: Templates with columns not contained upstream will display a warning. Please ensure the column is available upstream or is not misspelled to dismiss the warning. This will not prevent the component from executing.


More Information:

As said previously, the Pack Data Transform uses dotliquid as the templating engine. Documentation on the syntax can be found here:

https://github.com/Shopify/liquid/wiki/Liquid-for-Designers

https://shopify.github.io/liquid/basics/introduction/