EJS (Express.js) is a web application framework for Node.js. In BILLmanager EJS is implemented with the /usr/local/mgr5/etc/scripts/template_ejs.js script. For correct operation, the incoming XML-file is converted to a JSON file.
The EJS language describes document and message templates in BILLmanager. To add or edit templates, navigate to Settings → Document templates.
Comments and tags
There are two ways to add comments to templates:
- Use "/* <Comment text> */". Characters /* define the beginning of the comment, characters */ define its end. A single construction can contain multiple text strings.
- Use "// <Comment text>". A comment is a text after //, the comment ends with a line break.
In the template code, JavaScript expressions, HTML, and comments are put into special tags.
Variables
A variable declaration starts with the keyword var followed by the variable name, e.g. :
var myVariable;
The variable declaration ends with a semi-colon. The names of the variables in EJS-templates are case-sensitive: myVariable and myvariable are different variables.
Variable data type is defined bases on the value (optional):
var myText = 'Text variable'; //A string is put into single quotes.
var myNumber = 10; // Numeric data type. The value is specified without quotes.
var myBoolean = true; // Booling data type. true and false are key words, they are not put into quotes.
var myObject = document.querySelector('h1'); // This variable is used for saving the objects. It can keep any object of the billing system.
var myArray = [1, 'Payer', 2, 'Provider']; //Data array. It allows to keep many elements.
Contents
In EJS-template the information can be represented with the help of several elements:
- formatting blocks. The are specified with the tags <div> (...) </div>;
- tables. The are specified with the tags <table> (...) </table>;
- lists. The are specified with the tags <ul> (...) </ul>;
- links to images. The are specified with the tag <img src=(...)/>.
Document print layout is based on the elements and their formatting parameters described in the code.
For more information, please refer to the article Contents EJS-code.
Logical operators
Conditions in an EJS-template enable to check if a statement is true and execute a code fragment depending on its result.
For example, if the payer type is "Company", the system must show a VAT number in the printing document.
For more information about how to use logical operators in EJS-templates, please refer to the article Logical operators.
Functions
Functions allow using a certain piece of code multiple times without the need to write it again. You need to add a function only once and call the function in the code by its name.
For example, in the "date' function a developer described a piece of code to change the numerical value of a month into the letter symbols. This function can be used in the invoice name and payment purpose. You will only need to specify a function name.
For more information, please refer to the article Functions EJS-code.