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 list-support.
PTL v2 Replaces v1 and introduces support for the Mustache specification.

Support

Lang Variables Functions Looping Conditionals Nested conditionals
PTL v1 Yes No Yes No No
PTL v2 Yes Yes Yes Yes Yes

PTL v1

PTL version 1 has basic support for variable replacement and lists. The drawback is that it does not support conditionals. It is a good simple choice if you only need to replace a few variables and a list 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

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}}