RAD Studio 10.4.1 is now available! Learn more. Looking for discounts? Visit our Special Offers page!
CodeDelphi

Ultra-Fast Logic Less Template For Delphi Applications Using Synopse DMustache

Mustache is a Logic-Less Templates by Chris Wanstrath. Mustache can be used for HTML, config files, source code – anything. It is called as “logic-less” because there there are no if statements, else clauses, or for loops. Instead there are only tags. Some tags are replaced with a value, some nothing, and others a series of values. It works by expanding tags in a template using values provided in a hash or object. DMustache is a Delphi implementation of the Mustache templating language by Arnaud Bouchez and others.

Features :

  • It has a separate parser and renderer (so you can compile your templates ahead of time),The parser features a shared cache of compiled templates;
  • It passes all official Mustache specification tests – including all weird whitespace process;
  • It allows the data context to be supplied as JSON or our TDocVariant custom variant type;
  • Almost no memory allocation is performed during the rendering;
  • It is natively UTF-8, from the ground up, with optimized conversion of any string data;
  • Performance has been tuned, with benefit from SynCommons optimized code;
  • Each parsed template is thread-safe and re-entrant;
  • It follows the SOLID Open/Close principle so that any aspect of the process can be customized and extended (e.g. for any kind of data context);
  • It is perfectly integrated with the other bricks of our mORMot framework, ready to implement dynamic web sites with true MVC design, and full separation of concerns in the views written in Mustache, the controllers being e.g. interface-based services;

Version Supported : Delphi 6 up to Delphi 10.3.

License : This library is part of the Open Source mORMot framework, so is released under the same disjunctive tri-license giving you the choice of one of the three following sets of free software/open source licensing terms:

  • Mozilla Public License, version 1.1 or later;
  • GNU General Public License, version 2.0 or later;
  • GNU Lesser General Public License, version 2.1 or later.

Sample Code :

  1. Create a Windows VCL Application. Add the Downloaded Synopse/Dmustache source from Github and add to the project.
  2. Include SynCommons, SynMustache in your Unit uses clause.
  3. Declare variables of TMustache and Variant to Parse and Render. See the Sample Below for a simple Tag type Name and Value.

To know more about Sections, Partials and Internationalization Check out the full source code and documentation of DMustache here.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES