Skip to content
Docs

Multi-Output Targets

Multi-output targets produce multiple outputs from a single target definition — like mail merge.

Add a loop to your target:

targets:
letters:
output_file: "letter_{recipient}.pdf"
jinja_template: letter.jinja
loop:
loop_data: recipients
assign_to: recipient
data:
yaml_files:
data: recipients.yaml

Where recipients.yaml contains:

recipients:
- "John Doe"
- "Jane Doe"

Run mm letters to generate letter_John Doe.pdf and letter_Jane Doe.pdf.

AttributeDescription
loop_dataName of the array to iterate over
assign_toVariable name for each element

For more complex data:

recipients:
- name: "John Doe"
institution: "University of Virginia"
- name: "Jane Doe"
institution: "Brigham Young University"

Access properties in output_file and templates:

output_file: "letter_{recipient[name]}.pdf"

In your jinja template:

Dear {{ recipient.name }},
On behalf of {{ recipient.institution }}...

Generate mailto links for personalized emails:

data.yaml
people:
- first_name: Bob
email: bob@example.com
- first_name: Alice
email: alice@example.com
{# letter.jinja #}
{% for person in people %}
<a href="mailto:{{ person.email }}?subject=Hello&body=Hi {{ person.first_name }}">
{{ person.first_name }}
</a>
{% endfor %}
_markmeld.yaml
targets:
emails:
jinja_template: letter.jinja
output_file: emails.html
command: pandoc -o {output_file}
data:
yaml_files:
- data.yaml