2

I am looking for a template engine that satisfies the following requirements:

  1. General-purpose, i.e. not specialized for generating text in a specific language.

  2. Must handle indentation well, i.e. it should be relatively easy to control the indentation structure of the output when writing templates while also using indentation for readability of the template language itself. The engine should be able to distinguish "template indentation" from "output indentation" and to intelligently strip the former when generating output.

  3. Must be "literal text first", i.e. there must be no need to mark up "literal text" in any special way. This is a requirement satisfied by XML-like syntaxes among others, and emphatically NOT satisfied by pug-like syntaxes.

  4. Must support some kind of section / yield constructs; most abstractly, it must be possible to:

    • define named places / "extension points" in the output
    • append to different named places defined in independent template files from one place in a template
    • append from many places in templates to the same named place in the output

Planned application: generating Dockerfiles, nginx configs, and possibly other DSLs, to avoid tooling bloat of using a dedicated beautfier for each DSL.

1

Welcome to Software Recommendations! I may missunderstand you question, but I think this question does not appear to be about software recommendations, within the scope defined on meta and in the help center. If you think you can edit it to become on-topic, please have a look at the question quality guidelines.

Please try stackoverflow to get answers for topics that are relatic to software development.


That being said, i would recommend Jinja2, Nunjucks, Fluid or smarty

While samples in the docs (e.g. the docs of Jinja2) generally are in HTML, the Jinja docs states clearly:

Jinja can generate any text-based format (HTML, XML, CSV, LaTeX, etc.). A Jinja template doesn’t need to have a specific extension: .html, .xml, or any other extension is just fine.

Same is true for the others.

Jinja enable builtin whitespace control. For smarty, you may use this or customize it.

  • 1
    Thanks! I will check these. It seems that Jinja2 fails requirement 4.2 - it seems impossible to write a template file that appends text to multiple append points defined in multiple independent files. It is only possible to append to multiple append points defined in a single extends chain, i.e. to points defined in multiple files that are not independent. – Szczepan Hołyszewski Apr 24 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.