I'm generating plaintext emails with heavily personalized content: depending on various factors, sections or sentences need to be inserted, left out or phrased differently and placeholders need to be filled.
Currently I'm using Twig as a template engine, however the templates become very convoluted, because of the many nested
include statements and the fight to use the whitespace controls properly: The nested
if statements and their inner blocks sometimes can't be indented or separated because that would create unneccesary whitespace or blank lines. I wonder if there is a different way to assemble text snippets. My requirements are:
- Assemble text snippets based on certain conditions (some dependent on each other, some not)
- Be able to control paragraphs (i.e. blank lines) independently from the logic.
Optional features would be:
- Placeholder replacement
- Reflow of text to 75 char width, while keeping paragraphs
- Collapse of too many blank lines.