Edwin Yip 154 Posted July 16, 2021 (edited) For my new project I need a template engine for generating web pages, while I have concluded which suited my needs the best and I'm quite confident about my conclusion, your opinions and comments might help me to make my final decision. Since mORMot is my go-to framework for server-side web development, the first candidate to consider is obviously DMustache, which is a fast Delphi/FPC implementation of the popular logic-less Mustache template engine. Actually I've used it in several of my projects and it's great. But sometimes I need more features, but as you know, logic-less means no "if", "while", and so on. And fortunately I found Sempare Template Engine, which is the only feature-rich template engine for Delphi ( Yes, I meant it, because we all know Delphi was/is mostly focused on GUI development but not web development...) Pros === - Very very feature-rich, "if", "for and while loop", "include", "JSON", "custom methods", and so on. Basically, the feature set it's very close to template engines you can find in web-focused languages such as Java. No other Delphi template engine is even comparable (sorry, I love DMustache, but I also need "if" and "while"...). - Very well designed! You can tell by just looking at the unit namespaces and the source! - Documented, and with examples. - Well-tested (with DUnitX tests) Cons: While It's also open source, but for commercial uses you need to buy a license key with a very reasonable price. There are other template engines too, but IMHO, only DMustache and Sempare Template are serious, so I won't list them here... Your comments are welcomed! Edited July 16, 2021 by Edwin Yip 1 Share this post Link to post
Fr0sT.Brutal 900 Posted July 19, 2021 (edited) I use http://dvdchief.com/delphi with success. It's double-licensed GPL/MPL and have conditionals, expressions and loops. I also made some cosmetic modifications Edited July 19, 2021 by Fr0sT.Brutal Share this post Link to post
Edwin Yip 154 Posted July 19, 2021 @Fr0sT.Brutal, Thanks for the link! From the overview webpage the features seems to be quite powerful, but it doesn't seem to be compatible with my XE4 compiler: [dcc32/dcc64 Error] TemplateEngine.pas(2253): E2030 Duplicate case label Feature-set aside, it still has less documents and examples than Sempare Template. But thanks for the link! Share this post Link to post
Fr0sT.Brutal 900 Posted July 19, 2021 1 hour ago, Edwin Yip said: @Fr0sT.Brutal, Thanks for the link! From the overview webpage the features seems to be quite powerful, but it doesn't seem to be compatible with my XE4 compiler: [dcc32/dcc64 Error] TemplateEngine.pas(2253): E2030 Duplicate case label Feature-set aside, it still has less documents and examples than Sempare Template. But thanks for the link! Oh yep. I fixed that in my fork, here's the diff (IDK if it will apply onto initial file) TemplateEngine.pas | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/TemplateEngine.pas b/TemplateEngine.pas index aa8bb38..11a59ef 100644 --- a/TemplateEngine.pas +++ b/TemplateEngine.pas @@ -31,6 +31,7 @@ unit TemplateEngine; {$B-} //Boolean short-circuit evaluation {$O+} //Optimization on {$R-} //Range checking off +{$HIGHCHARUNICODE ON} {.$DEFINE SMARTYDEBUG} interface @@ -2307,7 +2308,7 @@ begin '>': Result := Result + '>'; '''': Result := Result + '''; '"': Result := Result + '"'; - { #160: Result := Result + ' '; + #160: Result := Result + ' '; #161: Result := Result + '¡'; #162: Result := Result + '¢'; #163: Result := Result + '£'; @@ -2555,7 +2556,7 @@ begin #9827: Result := Result + '♣'; #9829: Result := Result + '♥'; #9830: Result := Result + '♦'; -} else + else Result := Result + Ch; end; end; With the commit message "! Fixed compiling HTMLEncodeEntities under XE2, uncommented stuff. Dumb compiler behavior when in considers char constants ANSI" 😄 Share this post Link to post
Fr0sT.Brutal 900 Posted July 19, 2021 1 hour ago, Edwin Yip said: Feature-set aside, it still has less documents and examples than Sempare Template. They have pretty good help file and rich set of functions. Worth a try. Yes it seems abandoned but it's opensource with friendly license. Share this post Link to post
Markus Kinzler 174 Posted July 19, 2021 https://github.com/sempare/sempare-delphi-template-engine https://github.com/synopse/dmustache https://github.com/marcocantu/DelphiRazor Share this post Link to post
mvanrijnen 123 Posted July 19, 2021 I use sempare, work great for me, the creator is also here on the forum i believe. Share this post Link to post
Wagner Landgraf 43 Posted July 19, 2021 You can try https://github.com/arimateia/liquid-delphi which is a Delphi implementation of Liquid template engine. 1 Share this post Link to post
mvanrijnen 123 Posted July 20, 2021 I don't know directly from the others, but with Sempare you can make your own functions etc, very handy. Share this post Link to post
darnocian 87 Posted July 20, 2021 @mvanrijnen @Edwin Yip Thanks for the references. The aim with the Sempare Template Engine was to have a template engine that was native to Delphi and could be used for web, but also for other kinds of purposes such as code or config generation. At the time I wrote it, dmustache was mainly what was available, but I wanted a template language that was more readable and pascal-like, and from a library perspective providing more flexibility in terms of extension points (custom functions) and the ability to support various sub-template inclusion patterns (content with header/footer, main template referencing content template, etc) and dynamic loading. Due to the fact that looping is a feature, it also has to be safe and offers a timeout if template processing takes too long due to data processing or bad logic. It does rely on RTTI, which does mean there is a performance penalty, but I chose functionality/flexibility over performance to start. I have not had problems reported yet, so I suspect performance has been acceptable for users, as it has been for my use cases. Documentation wise, it should be fairly well covered on github, but I have been working on a CHM help edition which can be used from the IDE with context sensitive help which may be a bit more friendly for those that don't want to necessarily have to browse to the the github docs. Please email me conrad@sempare.ltd/conrad.vermeulen@gmail.com if you are interested and can notify you when it is available. If you have feature requests/comments feel free to raise them on the issue tracker (https://github.com/sempare/sempare-delphi-template-engine/issues). I do check here periodically, but may miss things or reply late. In the next release, I'm allowing for discovery of variables and functions that are referenced. So if you provide a template editor and are using a dictionary/json to pass variables, the UI can know upfront what the required variables are and perform additional validation if required, prompting the user if anything is missing. Alternatively, it could be a way to identify variables that are required, allowing for optimal querying of data from database before populating the template. This is just a complementary feature to an existing feature where errors can be raised if a referenced variable is not present. Further, I hope to create some more examples with more popular web frameworks soon, as I think many people find it easier to see how things work from demos. I realise licensing as GPL may be contentious, but I've gone with the 'free as in speech vs free as in beer' approach. So for a nominal one time fee, you can use it under the commercial license without any restriction. I'll keep you posted on new developments as they unfold. 4 Share this post Link to post
darnocian 87 Posted September 18 Hi all, I apologise for doing a double post, but some people don't see the posts everywhere. For any users, or anyone interested in the Sempare Template Engine, I would love to get some feedback from you to help with next steps in development on the project. The questionnaire is a bit general, as the objective is to guide the direction of this project and another I will be releasing soon as well. https://docs.google.com/forms/d/e/1FAIpQLScioIiDxvsWK01fMFqYr9aJ6KhCGeiw4UaU_esGuztEE7vYwA/viewform Thank you in advance. Regards, Conrad 1 Share this post Link to post
darnocian 87 Posted September 23 Again, sorry for the cross post: The Sempare Template Engine is now available under the Apache 2.0 licensing. Share this post Link to post
Anders Melander 1815 Posted September 23 1 hour ago, darnocian said: Again, sorry for the cross post: Why apologize when you are doing it on purpose? Share this post Link to post