Overview
A Template Macro is a reusable piece of template code that can be incorporated into various template configurations. For example, you can create your own header as a Template Macro and use it in multiple Reports, Invoices, and PrintDocs. Making a change to the Template Macro configuration will be automatically reflected in the other templates that utilize it, reducing the amount of duplicated work you have to do.
Configuration
Details
Title
The Title of your Template Macro must abide by standard variable naming conventions – it must start with an alphabetical letter and contain only letters, numbers, and underscores.
Editor Type
Only "Code" is available for the Editor Type of a Template Macro
Description
Meaningful description of your Template Macro. It is useful to jot down its purpose so you remember which templates could utilize it
Active
Whether or not the Template Macro is active. This is what makes it available to be used in your other templates
Design
This is the general design tab that you would see in other template editors. You can write your Jinja2/HTML code and use the preview functionality to see how it will look when converted to PDF. The important things to note here are the context variables. You must use the "Parameters" tab (explained in the next section) to provide context variables to your Template Macro.
Parameters
By default, Template Macros will not have context of any variables in your templates. You must explicitly define parameters that will be passed into your Template Macros as context variables. The types of variables you can choose between are Order, Sample, Test, and Anything. Use the third column (Example Value) for passing in test values when you are previewing your Template Macro. Similarly to the Title of the Template Macro, the name of your parameters must abide by standard variable naming conventions.
Versions
Like other template configurations, Template Macros incorporate versioning to properly keep track of your changes. When using a Template Macro within other templates, it will use the version that is active.
Example Usage 1 - Report Template (Visual Editor)
In the Visual Editor, there is a button titled "Insert Macro". Use this button to select your Template Macro and render its contents. You will prompted to input values for the parameters that you setup above. These values are not required and will be dependent on the usage of your template.
Example Usage 2 - PrintDoc (Code Editor)
In a Code Editor template, you can reference your Template Macro by Title. In our example above, the Title is "StandardHeader". The corresponding code you would use to insert your macro would be
{{ StandardHeader(header_title="Chain of Custody", sample=sample }}
You are able to use any Template Macro that is marked active.
Comments
0 comments
Please sign in to leave a comment.