有没有像Delphi或Velocity的模板引擎? [英] Is there a Template Engine like Velocity or Freemarker for Delphi?

查看:251
本文介绍了有没有像Delphi或Velocity的模板引擎?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Web应用程序,如果Delphi对象属性和方法可以与HTML代码连接,这将是有帮助的。



这可以在很多方面使用,在HTML响应构建阶段和请求处理阶段期间:




  • 访问服务器端对象属性值以将其输出到HTML代码

  • 将服务器端对象属性绑定到HTML表单输入字段,以便Web应用程序以其当前值发送HTML表单,并在客户端提交时将该属性设置为输入的值表单

  • 将HTML表单按钮绑定到服务器端对象方法,该方法将在客户端提交表单

$ b时执行
$ b

我没有找到一个本地Delphi库,这样可以更容易地将这样的HTML添加到Delphi对象绑定中。



我的问题: / p>

是否有脚本代码生成的模板引擎,如 Apache Velocity Freemarker (见下面的示例),我可以使用Delphi应用程序? (不在IDE中 - 我不是在寻找基于OTA的解决方案,或Delphi代码模板)



模板引擎会将Delphi对象绑定到模板并替换脚本变量,并根据对象中的值执行迭代/条件。模板可以嵌套(调用其他模板)。



典型的用例是动态生成HTML代码,但也适用于Delphi代码生成器。



速度示例:

 < HTML> 
< BODY>
您好$ customer.Name!
< table>
#foreach($ mud in $ mudsOnSpecial)
#if($ customer.hasPurchased($ mud))
< tr>
< td>
$ flogger.getPromo($ mud)
< / td>
< / tr>
#end
#end
< / table>

Freemarker示例:

 < html> 
< head>
< title>欢迎!< / title>
< / head>
< body>
< h1>欢迎$ {user}!< / h1>
< p>我们最新的产品:
< a href =$ {latestProduct.url}> $ {latestProduct.name}< / a>
< / body>
< / html>

与我正在寻找的类似的其他模板引擎是 Visual Studio的T4代码生成 Smarty

解决方案

请看看这里: http://dvdchief.com/delphi/
这是一个免费的模板引擎,用于delphi,如smarty对于php。


For web applications, it would be helpful if Delphi object properties and methods could be "connected" with HTML code.

This could be used in many ways, both during the HTML response build stage and the request processing stage:

  • access a server-side object property value to output it in the HTML code
  • bind a server-side object property to a HTML form input field, so that the web application sends the form HTML with its current value, and set the property to the entered value when the client submits the form
  • bind a HTML form button to a server-side object method, which will be executed when the client submits the form

I have not found a native Delphi library which would make it easier to add such HTML to Delphi object binding.

My question:

Is there a template engine for scripted code generation like Apache Velocity or Freemarker (see examples below) which I can use in Delphi applications? (not in the IDE - I am not lookig for a OTA based solution, or Delphi code templates)

The template engine would bind Delphi objects to a template and replace the script variables, and execute iterations / conditions based on values in the objects. Templates can be nested (call other templates).

A typical use case would be the dynamic generation of HTML code, but also work for Delphi code generators.

Velocity example:

<HTML>
<BODY>
Hello $customer.Name!
<table>
#foreach( $mud in $mudsOnSpecial )
   #if ( $customer.hasPurchased($mud) )
      <tr>
        <td>
          $flogger.getPromo( $mud )
        </td>
      </tr>
   #end
#end
</table>

Freemarker example:

<html>
<head>
  <title>Welcome!</title>
</head>
<body>
  <h1>Welcome ${user}!</h1>
  <p>Our latest product:
  <a href="${latestProduct.url}">${latestProduct.name}</a>!
</body>
</html>  

Other Template Engines which are similar to what I am looking for are Visual Studio's T4 Code Generation and Smarty.

解决方案

Please have a look here: http://dvdchief.com/delphi/ This is a free template engine for delphi like smarty for php.

这篇关于有没有像Delphi或Velocity的模板引擎?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆