Inja: A Template Engine for Modern C++
github.com
github.com
Or: what do I gain from intentionally limiting myself to a bespoke language that lacks many of the constructs of the language I’m writing the rest of my project in?
If I can’t be trusted to responsibly and successfully use that full language in templates, how can I be trusted to use it in all the rest of the code base?
It's very common for templates to be written by people who are not full developers. The HTML might be written by a designer, email-templates may be written by marketing etc.
By limiting the power of the template language to only data display and simple conditionals and loops, you can those people to write templates far easier and you can let them upload new versions whenever they want with much less worries and you don't have to go through your full code review process just to update an email template.
Template languages are still languages, and it’s easy for even seasoned developers to make errors that have to be corrected between ‘upload’ and whatever deployment looks like in this scenario. Forget to double-up the closing curly-brackets? Blammo.
I wonder how common it is in practice. Are there existing frameworks or (non-no/low code) CMSes that support that workflow? I.e. letting non-admins modify templates, ‘compiling’ them if necessary, running them over some sample input, and allowing iteration - before potentially breaking things in production?
Limiting the language to avoid having to do a full security audit - that’s a good point.
Not having to use one could be a use case, though IMO I don’t know if that’s compelling enough…
When SGML, since the begin of times, has entities/entity references (plus CDATA/RCDATA marked sections) for exactly that purpose. Plus, can actually encode/quote expanded text in a context-dependent way (eg attributes vs elements) and prevent or allow expansion of replacement text into <script> directed by allowed content models, and prevent other injections using HTML-aware templating.
Totally.
My hypothesis: people enjoy writing templating engines, which is why there are so many. And people especially enjoy inventing their own programming languages.
Templating engines are the perfect place for a web developer to dip their toes as gently as desired into language creation, in a format that’s kind of fun and is also immediately relevant and useful.
I use cppcms most of times but in some cases I use Seastar for high perf.
Is there a use case I don’t understand?
In C++ terms this is a library that generates HTML, not a template engine.
The result may or may not be valid HTML.
But - whoops - now you’ve got collision with C++ “macros” - which already has collision with Lisp “macros” and text editor / word processor macros - and “processor” which looks a lot like the C++ “preprocessor” and …
If it was called “modern templating for c++” I would agree.
I'm not sure whether I should be disappointed or relieved :D