/
Print Template

Print Template

Print Template

Preface 

The print template describes both static and dynamic content to be rendered and printed in ESC/P POS printer in a v2.x versions of the Retail Tab app.

 

Syntax 

The app is using a complete set of Mustache syntax for setting up dynamic content in the templates. Therefore, regular text are transmitted to the paper "as is" and the Mustache tags are processed and replaced with the text they generate before the entire data is sent to the printer.

In addition to Mustache tags, the template may also contain ESP/P printer-specific formatting tags, described below.

ESC/P Printer Formatting Tags 

These tags define the text and table formatting, switch the printer font, and print some extra elements such as image and barcodes. Just specify the tag inside your text.

 

Text Alignment and formatting 

Text alignment and formatting tags are always specified at the beginning of the line. They should be put into the square braces where at least one tag letter must be present. You can specify one or more tags from different formatting groups but one line can have only a single formatting style.

Text alignment group
Sets the text. alignment on the current line:

  • L - left alignment

  • C - center alignment

  • R - right alignment

Font size group
Changes the font size for the current line:

  • a - normal font

  • A - big font

Text underline modifier
If specified, underlines text for the entire line:

  • L - sets underline mode ON

Bold text modifier
If specified, all text will be rendered as bold

  • B - sets bold mode ON

Inversed text effect
If specified, text will be printed as white characters on black background

  • I - sets inversed mode ON

Example:

Hello World - prints "Hello World" in with the default printer settings

[C]Hello World - prints "Hello World" text with a default font size and centered on paper

[CB]Hello World - prints "Hello World" with bold text of normal size and centered on paper

[ARU]Bye! - prints "Bye!" with a big font, underlined and aligned to the right side of the paper

 

The formatting modifiers specified are applied to the current line only. Next line, if specified without any modifiers, will be printed using default printer settings - typically normal font size, no effects, left aligned.

Multiple columns per line (aka table mode) 

To print multiple columns per line you must begin your line with the comma-separated column definition values, surrounded with the curly braces, for example: {2,6,4}

  • Every value defines how many grid elements should this column reserve from the total grids, available for the line.

  • There are a total of 12 grid elements, available for the line.

  • The sum of all values from all defined columns should be equal to 12

Next to the column definition, you may place your text. Columns should be separated by the vertical line - | - and every column may contain its own formatting tags, described above.

For example, if you want to print a typical receipt row consisting of 3 columns like No, Description, and the Price, you can specify it as follows:

{2,8,2} [L]No | [C]Description | [R] Amount
{2,8,2} [L]1. | [C] Coke | [R] $2.99
{2,8,2} [L]2. | [C] Beer | [R] $3.50
{2,8,2} [L]3. | [C] Chips | [R] $0.99

This will render the following output:

Coke $1.99 PHP detected Beer $3.50 PHP detected Chips $10.99 PHP detected

 

Images 

You can print images by referencing an image URL in the template, prefixed with the triple "@" characters. Note that such an image reference must be on its own line and contain any other text or variables.

 

Example:

[C]My Shop @@@https://icons-for-free.com/iconfiles/png/512/check+one-1324760547245977331.png Ruby detected

 

Document Variables - dynamic data 

Every template is loaded with the data from the document it prints. If you prints the Sales Invoice, all its data will be available to be referenced in the template.

To reference a variable, use Mustache {{}} syntax (double curly braces), for instance:

App version: {{app.version}}
Invoice number: {{invoice.number}}

 

To render the collection of data (for instance - invoice items) use corresponding Mustache's iteration syntax:

{{#invoice.items}}
{2,8,2}[L] {{index}} | [C]{{name}} | [R]{{totalValue}}
{{/invoice.items}}

 

Global Data 

These variables are present for in any template, regardless of what document you print.

App Data - provides application information:

  • app.version - version of the app

  • app.clientTraceId - client trace ID of this device

  • app.device - model of the device

  • app.android - version of the Android OS

User Data - provides logged-in user information:

  • user.name - logged-in user name

  • user.endpoint - server address

  • user.tenant - tenant name

  • user.login - logged-in user login

  • user.location - location code for the user

 

Context-specific data 

These variables are present only if the template for the particular document type.

Sales Invoice:

 

Sales Return:

 

Conditions 

Use the # symbol for 'if' so assuming your variable is {{example}} then

{{#example}} Start condition if example exists {{/example}} C/C++ detected

And ^ works the same way for 'if does not exist'

{{ ^example}} Start condition if example does not exist {{/example}}

Related content