Template Engine Reference

Comprehensive documentation for the LogicPaper formatting engine. Learn how to transform raw Excel/CSV/JSON data using Jinja2 Pipes directly inside your Word, PowerPoint, Markdown or Plain Text templates.

Default Behavior

What happens if I don't use a formatter?

If you use without a pipe (|), LogicPaper inserts the Raw Data exactly as it appears in the Excel cell.

Examples:

  • Dates may appear as 2023-12-25 00:00:00.
  • Money may appear as 1500.5 (no symbol, no comma).
  • Empty cells will appear as empty strings.

Chaining & Composition

You can apply multiple operations in a single filter by listing them as arguments. Operations are executed sequentially from left to right.

// Syntax
{{ variable_name | filter_name('Op1', 'Op2', 'Op3') }}
// Example: Clean, Uppercase, and Add Prefix
{{ client_name | format_string('trim', 'upper', 'prefix', 'MR. ') }}
Input " john doe "
Process Flow trim → upper → prefix
Final Output "MR. JOHN DOE"

String Strategy

Filter Name: format_string

Operation Full Template Syntax (Click to Copy) Input Data Output Result Technical Details
Upper
{{ val | format_string('upper') }}
text "hello" "HELLO" Converts entire string to uppercase.
Lower
{{ val | format_string('lower') }}
text "HELLO" "hello" Converts entire string to lowercase.
Title Case
{{ val | format_string('title') }}
text "mr john doe" "Mr John Doe" Capitalizes the first letter of every word.
Swap Case
{{ val | format_string('swapcase') }}
text "PyThon" "pYtHON" Inverts casing.
Trim
{{ val | format_string('trim') }}
text " data " "data" Removes leading and trailing whitespace.
Reverse
{{ val | format_string('reverse') }}
text "abc" "cba" Reverses character order.
Prefix
{{ val | format_string('prefix', 'Dr. ') }}
text "House" "Dr. House" Prepends text.
Suffix
{{ val | format_string('suffix', ' Esq.') }}
text "John" "John Esq." Appends text.
Truncate
{{ val | format_string('truncate', '10') }}
text "Long Text Here" "Long Text..." Cuts text if exceeds limit.
Snake Case
{{ val | format_string('snake') }}
text "Logic Paper" "logic_paper" Converts to snake_case.
Kebab Case
{{ val | format_string('kebab') }}
text "Logic Paper" "logic-paper" Converts to kebab-case.
Slug
{{ val | format_string('slug') }}
text "H&M Project!" "hm-project" URL-friendly slug (removes special chars).
Chained
{{ val | format_string('trim', 'upper', 'prefix', 'ID: ') }}
text " abc " "ID: ABC" Composition: Trim → Upper → Prefix.

Number & Currency

Filter Name: format_number

Operation Full Template Syntax Input Data Output Result Technical Details
Integer
{{ val | format_number('int') }}
float 15.99 "15" Truncates decimals.
Float
{{ val | format_number('float', '2') }}
num 1500 "1500.00" Forces N decimal places.
Round
{{ val | format_number('round', '0') }}
num 3.6 "4" Rounds to precision.
Separator
{{ val | format_number('separator', '.,') }}
num 1234.5 "1.234,50" EU/BR Format (Dot thousands, Comma decimal).
Currency (USD)
{{ val | format_number('currency', 'USD') }}
num 1500 "$1,500.00" Locale aware formatting for US Dollar.
Currency (BRL)
{{ val | format_number('currency', 'BRL') }}
num 1500 "R$ 1.500,00" Locale aware formatting for Brazilian Real.
Percent
{{ val | format_number('percent') }}
num 0.25 "25%" Multiplies by 100.
Scientific
{{ val | format_number('scientific') }}
num 1000 "1E3" Scientific notation.
Humanize
{{ val | format_number('humanize') }}
num 1500000 "1.5M" Short scale notation (K, M, B).
Ordinal
{{ val | format_number('ordinal') }}
int 3 "3rd" Ordinal number conversion.
Spell Out
{{ val | format_number('spell_out', 'en') }}
int 42 "forty-two" Numbers to words. Supports 'en', 'pt', 'es'.

Date Strategy

Filter Name: format_date

Operation Full Template Syntax Input Data Output Result Technical Details
ISO Standard
{{ val | format_date('iso') }}
date 2025-12-25 "2025-12-25" Universal ISO 8601 format.
Short
{{ val | format_date('short', 'en') }}
date 2025-12-25 "12/25/25" Req. Locale.
Medium
{{ val | format_date('medium', 'en') }}
date 2025-12-25 "Dec 25, 2025" Req. Locale.
Long
{{ val | format_date('long', 'pt') }}
date 2025-12-25 "25 de dezembro..." Req. Locale.
Full
{{ val | format_date('full', 'en') }}
date 2025-12-25 "Thursday, December..." Req. Locale.
Custom Pattern
{{ val | format_date('fmt', '%d/%m') }}
date 2025-12-25 "25/12" Uses Python strftime syntax.
Year
{{ val | format_date('year') }}
date 2025-12-25 "2025" Extracts only the year.
Month Name
{{ val | format_date('month_name', 'en') }}
date 2025-12-25 "December" Full Month Name. Req Locale.
Add Days
{{ val | format_date('add_days', '7') }}
date 2025-01-01 "2025-01-08" Arithmetic.
Add Years
{{ val | format_date('add_years', '1') }}
date 2025-01-01 "2026-01-01" Arithmetic.

Logic & Defaults

Filter Name: format_logic

Operation Full Template Syntax Input Data Output Result Technical Details
Default Value
{{ val | format_logic('default', 'N/A') }}
null (empty) "N/A" Used when Excel cell is empty.
Mapping
{{ val | format_logic('1=Active', '0=Inactive') }}
int 1 "Active" Maps Keys to Values.
Empty If
{{ val | format_logic('empty_if', '0') }}
int 0 "" Hides the value if it matches the argument.
Fallback
{{ val | format_logic('1=Yes', 'Other') }}
int 5 "Other" Implicit "Else" value.

Boolean Strategy

Filter Name: format_bool

Operation Full Template Syntax Input Data Output Result Technical Details
Bool
{{ val | format_bool('bool') }}
int 1 "True" Converts 0/1 to True/False string.
Custom Map
{{ val | format_bool('bool', 'Yes', 'No') }}
bool TRUE "Yes" Arg 1 is True value, Arg 2 is False value.
Checkbox
{{ val | format_bool('check') }}
bool TRUE "☑" Visual checkbox character.

Privacy & Masking

Filter Name: format_mask

Operation Full Template Syntax Input Data Output Result Technical Details
Mask
{{ val | format_mask('mask', '###-##') }}
text "12345" "123-45" Generic pattern.
Email
{{ val | format_mask('email') }}
text "admin@corp.com" "a***@corp.com" Obfuscates user part.
Credit Card
{{ val | format_mask('credit_card') }}
text "1234...5678" "**** 5678" Last 4 digits only.
Name
{{ val | format_mask('name') }}
text "John Doe" "J*** D***" Initials + ***.

Dynamic Images

Filter Name: format_image

Method 1: Template Filter (Word Only)

Use this method to insert images directly into a paragraph using Jinja2 syntax. The image file must be present in the uploaded assets.zip.

Syntax Description
{{ val | format_image('5', '3') }}
Resizes to 5cm Width x 3cm Height.
{{ val | format_image('5', 'auto') }}
Width 5cm, auto height.

Method 2: Shape Replacement (Word & PowerPoint)

This is the best method for design precision. Create a placeholder shape (Rectangle, Circle, or generic Picture) in your document.

  1. Insert a Shape or Picture in Word/PowerPoint.
  2. Right-click and select View Alt Text (or use Selection Pane to rename it).
  3. Enter the exact filename of your image asset (e.g., photo.jpg or logo.png).
  4. LogicPaper will replace the shape with the image, matching its size and position.
Tip: This works perfectly for profile circular photos, slide backgrounds, or precise grid layouts.

Conditional Logic (Word Only)

Control visibility of text, paragraphs, and tables.

These tags allow you to use If/Else logic. They currently work only in Word (.docx) templates.
Operation Full Template Syntax (Click to Copy) Input Data Output Result Technical Details
Paragraph
{%p if show_details %}
... content ...
{%p endif %}
bool show: false (Removed) Removes entire paragraph including line breaks.
Inline
Status: {% if active %}Active{% else %}Inactive{% endif %}
bool active: true Status: Active Hides specific words within a sentence.
Table Row
| {%tr if qty > 0 %} | Item |
int qty: 0 Hidden Removes the entire table row. Tag must be in first cell.

Dynamic Tables (Word Only)

Generate rows automatically from Excel/CSV/JSON lists.

Use this to turn a list of items (e.g., Invoice Items, product lists) into a Word table.

How to setup in Word:

Product Quantity Price
{%tr for item in sales_data %}
{{ item.product }} {{ item.quantity }} {{ item.price }}
{%tr endfor %}

Input Data (JSON)

{
    "report": "sales",
    "sales_data": [
        {
            "product": "Monitor",
            "quantity": 2,
            "price": 850.00
        },
        {
            "product": "Keyboard",
            "quantity": 5,
            "price": 320.50
        },
        {
            "product": "Mouse",
            "quantity": 10,
            "price": 145.90
        },
        {
            "product": "Headset",
            "quantity": 3,
            "price": 550.00
        }
    ]
}

Output Result (Word Table)

Product Quantity Price
Monitor 2 850.0
Keyboard 5 320.5
Mouse 10 145.9
Headset 3 550.0
  1. Create a table with 1 Header Row and 1 Data Row.
  2. Start Row: Contains {%tr for item in sales_data %}.
  3. Data Row: Contains variables like {{ item.product }}.
  4. End Row: Contains {%tr endfor %}.
  5. LogicPaper will duplicate the data row for every item in text.
Code copied to clipboard!