4 ms·
Ask HN: Document templating for automation
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?
- imonroe 9y agoIf you're using python, maybe jinja would work. I like twig in PHP, but that's because I like php.
- mtmail 9y agoAlmost 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_engines https://en.wikipedia.org/wiki/Comparison_of_web_template_eng... 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 9y agoYou 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.