Skip to content

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

PTL v1 varible (template+model)
<!-- template -->
Hello [NAME]

<!-- model -->
{
  "NAME" = "John"
}
Produces the following markup
Hello John

Conditionals

PTL v1 if statement checking if variable is truthy (template+model)
<!-- template -->
[[IF]]([NAME])
    Hello [NAME]!
[[ELSE]]
    Hello, what is your name?
[[ENDIF]]

<!-- model -->
{
  "NAME" = ""
}
Produces the following markup
Hello, what is your name?
PTL v1 if statement value comparison (template+model)
<!-- 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'
}
Produces the following markup
Hello John!
You are already subscribed!

Lists

PTL v1 list (template + model)
<!-- template -->
[ITEMS].each do
<li>
    <i>[ITEMS_ITEM]</i>
</li>
end

<!-- model -->
{
  "ITEMS" = [1,2,3]
}
Produces the following markup
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

PTL v2 variables (template+model)
<!-- template -->
Hello <b>{{NAME}}</b>

<!-- model -->
{
  "NAME" = "John"
}
Produces the following markup
Hello <b>John</b>

Conditionals

PTL v2 conditionals non-false and false values (template+model)
<!-- 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
}
Produces the following markup
Hello <b>stranger</b>, nice to meet you!

Lists

PTL v2 list (template + model)
<!-- template -->
{{#ITEMS}}
  Item: <i>{{.}}</i>
{{/ITEMS}}

<!-- model -->
{
  "ITEMS" = [1,2,3]
}
Produces the following markup
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.

Migrate to ptl v2 from ptl v1
<!-- ptl v1 template -->
Hello [NAME]

[ITEMS].each do
  Item: <i>[ITEMS_ITEM]</i>
end

<!-- ptl v2 template -->
Hello {{NAME}}

{{#ITEMS}}
  Item: <i>{{.}}</i>
{{/ITEMS}}