Multi-Output Targets
Multi-output targets produce multiple outputs from a single target definition — like mail merge.
Quick start
Section titled “Quick start”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.yamlWhere recipients.yaml contains:
recipients: - "John Doe" - "Jane Doe"Run mm letters to generate letter_John Doe.pdf and letter_Jane Doe.pdf.
Loop attributes
Section titled “Loop attributes”| Attribute | Description |
|---|---|
loop_data | Name of the array to iterate over |
assign_to | Variable name for each element |
Array of objects
Section titled “Array of objects”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 }}...Example: Email mail merge
Section titled “Example: Email mail merge”Generate mailto links for personalized emails:
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 %}targets: emails: jinja_template: letter.jinja output_file: emails.html command: pandoc -o {output_file} data: yaml_files: - data.yaml