PTL - Payway Templating Language¶
Target Audience: Users, Developers
Introduction¶
PTL is a templating language used in Tulo Payway to edit HTML markup.
Version | Description |
---|---|
PTL v1 | Introduces variable substitution and simple logical operations |
PTL v2 | Replaces v1 and introduces support for the Mustache specification |
Support¶
Lang | Variables | Functions | Looping | Conditionals | Nested conditionals |
---|---|---|---|---|---|
PTL v1 | Yes | No | Yes | Yes | No |
PTL v2 | Yes | Yes | Yes | Yes | Yes |
PTL v1¶
PTL version 1 has basic support for variable replacement and simple boolean operations. The drawback is that it does not support nested conditionals. It is a good simple choice if you only need to replace a few variables and maybe an if statement or two. Otherwise we recommend version 2.
Variables¶
<!-- template -->
Hello [NAME]
<!-- model -->
{
"NAME" = "John"
}
Hello John
Conditionals¶
<!-- template -->
[[IF]]([NAME])
Hello [NAME]!
[[ELSE]]
Hello, what is your name?
[[ENDIF]]
<!-- model -->
{
"NAME" = ""
}
Hello, what is your name?
<!-- template -->
[[IF]]([PRODUCT_CODE] == 'adp_web')
Hello [NAME]!
You have purchased ADP Web. Maybe you would also be interested in ADP Print?
[[ELSE]]
Hello [NAME]!
You are already subscribed!
[[ENDIF]]
<!-- model -->
{
"NAME" = "John",
"PRODUCT_CODE" = 'adp_print'
}
Hello John!
You are already subscribed!
Lists¶
<!-- template -->
[ITEMS].each do
<li>
<i>[ITEMS_ITEM]</i>
</li>
end
<!-- model -->
{
"ITEMS" = [1,2,3]
}
Item: <i>1</i>
Item: <i>2</i>
Item: <i>3</i>
PTL v2¶
PTL version 2 is the second iteration of PTL and it introduces significant changes compared to v1 both in logical operations and syntax. Instead of extending the first version we decided to adhere to the Mustache specification. It emphasises logic-less templates. So instead of relying on complex if-else-whatnot statements you make decisions solely on what variables or tags the model has.
Variables¶
<!-- template -->
Hello <b>{{NAME}}</b>
<!-- model -->
{
"NAME" = "John"
}
Hello <b>John</b>
Conditionals¶
<!-- template -->
{{#NAME}} <!-- Checks if key does exist and is a non-false value, and not a list. -->
Hello <b>{{NAME}}</b>
{{/NAME}}
{{^NAME}} <!-- Checks if key doesn't exist, is a false-value, or is an empty list. -->
Hello <b>stranger</b>, nice to meet you!
{{/NAME}}
<!-- model -->
{
"NAME" = null
}
Hello <b>stranger</b>, nice to meet you!
Lists¶
<!-- template -->
{{#ITEMS}}
Item: <i>{{.}}</i>
{{/ITEMS}}
<!-- model -->
{
"ITEMS" = [1,2,3]
}
Item: <i>1</i>
Item: <i>2</i>
Item: <i>3</i>
Migrating to a new PTL version¶
When migrating to a new PTL version you will need to update the template to adhere to the new syntax. This is usually a case of find-replacing the surrounding tags.
<!-- ptl v1 template -->
Hello [NAME]
[ITEMS].each do
Item: <i>[ITEMS_ITEM]</i>
end
<!-- ptl v2 template -->
Hello {{NAME}}
{{#ITEMS}}
Item: <i>{{.}}</i>
{{/ITEMS}}