5 ms·
For those of us unfamiliar with this stuff, would it be accurate think of a "template engine" as a sophisticated "printf"?
by sigjuice 9y ago
For those of us unfamiliar with this stuff, would it be accurate think of a "template engine" as a sophisticated "printf"?
- praneshp 9y agoLittle bit more than a single printf. For example you can do loops. https://stackoverflow.com/questions/17691838/range-in-jinja2-inside-a-for-loop https://stackoverflow.com/questions/17691838/range-in-jinja2...
- dangerbird2 9y agoA templating engine does a few things differently than printf. Typically, it will compile into an intermediate version, for scripting languages like python as a module or object in the language. Most importantly, it escapes the input to prevent arbitrary HTML injection, for example a user inserting a <script> tag in a blog post content causing the javascript to be evaluated. Often, template engines have features for making it easier to design web user interfaces such as template inherritence and composition so you can share things like layouts, headers, and menus across pages.
- sametmax 9y ago+1. It can deal with non dev creating templates. It can compose templates. Manage caching. Embed logic. Debugging.
- dec0dedab0de 9y agosibling comments gave a much better explanation, but if you want to boil it down I think of it as python pretending to be PHP.