Hi All,
Just a quick ping that an update to the Sempare Template Engine is now available... v1.7.7
It is also available on GetIt. Please star the project if you havn't already. (Thanks)
Also for those watching Delphi Dev Days (https://www.codegear.com/DevDaysofSummer/) ... There will be a video posted today (15 Aug) with some demos showing some features and how easily the template engine can be included into projects...
https://github.com/sempare/sempare-delphi-template-engine
Changes:
- fixed a few things
- new 'functional includes' syntatic sugar
- release mode builds will fail if the license confirmation is not acknowledged
- also fully CI enabled now on github
... what is a functional include...
Lets say we have a main template where we are creating an html form:
<form method=post action=/register>
Name: <input name=name>
E-mail: <input name=email>
<input type=submit value=register>
</form>
so what we could do from a templating perspective:
<% template 'input' %>
<% label %>: <input name=<% name %>>
<% end %>
<% template 'button' %>
<% label %>: <input type=<% type %>>
<% end %>
<form method=post action=/register>
<% input { label="Name", name="name" } %>
<% input { label="E-mail", name="email" } %>
<% button { label="register", type="submit" } %>
</form>
So above, you can see that we can have 'inline templates' that are named 'input' and 'button'. In the form section, the 'functional include' syntax is then used to pass the params...
The alternative way of doing the include traditionally is a bit more verbose, but essentially the same:
<form method=post action=/register>
<% include 'input', { "label": "Name", "name": "name" } %>
<% include 'input', { "label": "E-mail", "name": "email" } %>
<% include 'button', { "label": "register", "type": "submit" } %>
</form>
The above is a bit more verbose, passing a dictionary, whereas the 'functional include' syntax can be a bit more pretty on the eye...
So the nice thing then is that the inline templates could be moved out to separate files. The template registry can then be configured to load the various templates as required - from disk, resources, db, etc... Custom styling, etc can then be localised to the specific 'atomic' template. This works quite nicely when using stuff like TailwindCSS (https://tailwindcss.com/) , which lends itself to styles being inline rather than being in CSS files...
Anyways, have fun. Please support me if you can.