Skip to content

First files

This page takes you from nothing to text, Markdown and Word files in a few minutes. Open a terminal in the examples/ folder.

The data

employees.xlsx (and the same rows in employees.json). The first row holds the column names:

id name department city salary hired email
1 Abdullah Sales Homs 1200 2021-04-01 abdullah@example.com
2 Rawaa IT Damascus 1800 2023-09-15 rawaa@example.com
3 Rama IT Homs 1500 2024-02-10 rama@example.com
4 Omar Sales Aleppo 1100 2024-11-03

Omar has no email: that empty cell matters in a few examples.

The example files

File What it is Used in
employees.xlsx, employees.json The 4 rows above everywhere
rama.json One record (a JSON object) --object
person.schema.json A JSON Schema to type people in Data sources, Stores
welcome.txt A two-line welcome note this page
names.txt Every name on one line Order and filter
team.md A Markdown team table with a total Render modes
report.md A report with a title from the command line Templates
letter.md A letter for one record Render modes
email.txt A welcome email Recipes
department.html, department.md One page per department Grouping
by-city.txt A report of groups Grouping
profile.json, all.json, export.json JSON output JSON templates, Excel to JSON
offer.docx A Word offer letter Word
all-offers.docx Every person in one Word file, one page each Word
staff-table.docx A Word table, one row per person Word
certificate.docx A certificate for one record Word, Stores
salary-certificate.md An Arabic salary certificate Type filters

A text file per person

welcome.txt:

Hello {{ name }},
You joined {{ department }} on {{ hired.strftime("%d/%m/%Y") }}.

The column names are the variables. Render one file per row:

templify render --each -t welcome.txt -d employees.xlsx -o welcome -n name
4 files generated successfully in: .../examples/welcome

welcome/Rama.txt:

Hello Rama,
You joined IT on 10/02/2024.
  • --each writes one file per row.
  • -o welcome is the output folder. It is created if it does not exist.
  • -n name names each file after the name column: Rama.txt.

One Markdown report of everyone

team.md loops over all the rows, which are in the variable objects:

# Team report

| # | Name | Department | Salary |
|---|------|------------|-------:|
{% for e in objects -%}
| {{ loop.index }} | {{ e.name }} | {{ e.department }} | {{ "{:,}".format(e.salary) }} |
{% endfor %}
**Total salaries:** {{ objects | sum(attribute="salary") }}

Without --each, templify writes one file:

templify render -t team.md -d employees.xlsx -o reports --order -salary

reports/team.md:

# Team report

| # | Name | Department | Salary |
|---|------|------------|-------:|
| 1 | Rawaa | IT | 1,800 |
| 2 | Rama | IT | 1,500 |
| 3 | Abdullah | Sales | 1,200 |
| 4 | Omar | Sales | 1,100 |

**Total salaries:** 5600

--order -salary sorts by salary, highest first.

Word letters

offer.docx is a normal Word document with Jinja tags typed into it:

Job offer

Dear {{ name }},

We are happy to welcome you to the {{ department }} team in our {{ city }} office.
Your monthly salary is {{ "{:,}".format(salary) }} USD, starting on
{{ hired | date.strftime("%d %B %Y") }}.
templify render --each -t offer.docx -d employees.xlsx -o offers -n name --numbered
offers/
├── 1 - Abdullah.docx
├── 2 - Rawaa.docx
├── 3 - Rama.docx
└── 4 - Omar.docx

--numbered adds the row number in front, so the files stay in data order.

Running it twice

Run the first command again, and templify does not overwrite anything: the new files get a short random suffix, like Rama-3f9a1c2e.txt. See Output files.

Next

Learn the three render modes.