delphi模板引擎

delphi模板引擎

开源地址:https://github.com/sempare/sempare-delphi-template-engine

可能适用的场景:

  • 使用模板引擎(或语言)的网站
  • 代码生成
  • 邮件合并
  • 通知消息

用法示例:

program Example;
uses
    Sempare.Template;
type
    TInformation = record
        name: string;
        favourite_sport : string;
        count : integer;
    end;
begin
    var tpl := Template.Parse(
           'My name is <% name %>.'#13#10 + 
           'My favourite sport is <% favourite_sport %>.'#13#10 + 
           'Counting... <% for i := 1 to count %><% i %><% betweenitems %>, <% end %>'
    );
    var info : TInformation;
    info.name := 'conrad';
    info.favourite_sport := 'ultimate';
    info.count := 3;
    writeln(Template.Eval(tpl, info));    
end.

 

posted @ 2023-01-03 09:43  delphi中间件  阅读(281)  评论(0编辑  收藏  举报