
Ask HN: Document templating for automation - ryeguy_24
I’m trying to build an automatic document generation process and have multiple types of documents to automate. These documents will have standard language but also dynamic language. I’m looking for a template engine similar to the templating used in current web frameworks (e.g. React uses curly brackets to escape and execute an expression within HTML or for control flow). I’m looking for something similar so I can embed some logic in the document output. For example, if a certain variable is less than zero, a different paragraph is displayed rather than a standard paragraph. Any ideas or technologies to leverage here?
======
mtmail
Almost every programming language has one or more libraries for templating.
That's how PHP started early on. The author started with if/then, then added
loops ... and users demanded more and more features.

[https://en.wikipedia.org/wiki/Comparison_of_web_template_eng...](https://en.wikipedia.org/wiki/Comparison_of_web_template_engines)

Have a look at
[https://github.com/wycats/handlebars.js/](https://github.com/wycats/handlebars.js/)
based on [http://mustache.github.io/](http://mustache.github.io/) which has
libraries for many programming languages.

------
cpburns2009
You haven't specified a language preference so I'll give you my preferred
choice: Mako templates for Python. It feels similar to PHP but with more
features such as:

\- Inline expressions with filter functions. Mako uses _${expression |
filter}_

\- Reusable template blocks which can be called like functions. Mako uses _<
%def>_ and _< %block>_.

\- Supports full Python expressions instead of a limited subset like Jinja.

------
imonroe
If you're using python, maybe jinja would work. I like twig in PHP, but that's
because I like php.

