StringTemplate和FreeMarker之间的主要区别是什么?

时间:2020-11-29 09:11:35

The net seems to be full of comparisons between Velocity and FreeMarker, and they seem to be reasonably equivalent. But there seems to be almost no comparisons between StringTemplate and FreeMarker!

网似乎充满了Velocity和FreeMarker之间的比较,它们似乎相当合理。但似乎几乎没有StringTemplate和FreeMarker之间的比较!

So, what are the main differences between StringTemplate and FreeMarker?

那么,StringTemplate和FreeMarker之间的主要区别是什么?

My usage for them would be to generate HTML pages only. Out of the two, I would've expected FreeMarker to be the more suitable and more capable, as that seems to the more common one - but through a quick glance it seems that StringTemplate actually has more suitable features!

我对它们的用法是仅生成HTML页面。在这两个中,我会期望FreeMarker更合适,更有能力,因为这似乎更常见 - 但通过快速浏览一下,看起来StringTemplate实际上有更合适的功能!

It would be great if someone who has used both would have time to comment - for the actual specifics, I can just read the documentation side by side, but I'd like something to get started with.

如果使用过两者的人都有时间发表评论会很棒 - 对于实际细节,我可以并排阅读文档,但我想要开始使用。

2 个解决方案

#1


30  

I designed ST to build jGuru after getting sick of the "code in template" model of JSP. Velocity and friends (i.e., every other engine i think) give you more power than you need. I used basically four features to build jGuru.com (as described in paper). More features are unnecessary and lead you to entangle your model into the template. If you're building a one-off prototype, that's ok and any engine is fine. Code in templates is ok in that case since you don't care about maintenance.

我设计了ST来构建jGuru之后厌倦了JSP的“模板代码”模型。速度和朋友(即我认为的每一个其他引擎)都会给你更多的力量。我基本上使用了四个功能来构建jGuru.com(如文中所述)。更多功能是不必要的,并导致您将模型纠缠到模板中。如果您正在构建一次性原型,那没关系,任何引擎都可以。在这种情况下,模板中的代码是可以的,因为您不关心维护。

Another thing people seem to ignore: how the hell can a graphics designer read code in templates? They can't. So, how can they work on the templates then? Even changing the order of some elements can break your model. You really need the separation to work in commercial environment, unless you want a site that looks like a coder built the html ;)

人们似乎忽略了另一件事:图形设计师如何在模板中读取代码?他们不能。那么,他们如何处理模板呢?即使改变某些元素的顺序也会破坏你的模型。你真的需要分离才能在商业环境中工作,除非你想要一个看起来像编码器的网站构建html;)

#2


6  

The main difference is that StringTemplate strictly enforces model-view separation and you can't put logic in the templates and FreeMarker lets you put full of logic in the templates.. This at least at the beginning make it more difficult to use but it's more scalable. For example if you are generating code and you have no logic in the templates generating another port for another language is less tedious because you haven't to replicate logic in each template.

主要区别在于StringTemplate严格执行模型 - 视图分离,你不能在模板中放置逻辑,FreeMarker允许你在模板中放入充分的逻辑。这至少在开始时使它更难以使用,但它更多可扩展性。例如,如果您正在生成代码并且模板中没有逻辑,则为另一种语言生成另一个端口不那么繁琐,因为您不必在每个模板中复制逻辑。

There's a paper from Terence Parr that explains the benefits from model-view separation

Terence Parr的论文解释了模型 - 视图分离的好处

#1


30  

I designed ST to build jGuru after getting sick of the "code in template" model of JSP. Velocity and friends (i.e., every other engine i think) give you more power than you need. I used basically four features to build jGuru.com (as described in paper). More features are unnecessary and lead you to entangle your model into the template. If you're building a one-off prototype, that's ok and any engine is fine. Code in templates is ok in that case since you don't care about maintenance.

我设计了ST来构建jGuru之后厌倦了JSP的“模板代码”模型。速度和朋友(即我认为的每一个其他引擎)都会给你更多的力量。我基本上使用了四个功能来构建jGuru.com(如文中所述)。更多功能是不必要的,并导致您将模型纠缠到模板中。如果您正在构建一次性原型,那没关系,任何引擎都可以。在这种情况下,模板中的代码是可以的,因为您不关心维护。

Another thing people seem to ignore: how the hell can a graphics designer read code in templates? They can't. So, how can they work on the templates then? Even changing the order of some elements can break your model. You really need the separation to work in commercial environment, unless you want a site that looks like a coder built the html ;)

人们似乎忽略了另一件事:图形设计师如何在模板中读取代码?他们不能。那么,他们如何处理模板呢?即使改变某些元素的顺序也会破坏你的模型。你真的需要分离才能在商业环境中工作,除非你想要一个看起来像编码器的网站构建html;)

#2


6  

The main difference is that StringTemplate strictly enforces model-view separation and you can't put logic in the templates and FreeMarker lets you put full of logic in the templates.. This at least at the beginning make it more difficult to use but it's more scalable. For example if you are generating code and you have no logic in the templates generating another port for another language is less tedious because you haven't to replicate logic in each template.

主要区别在于StringTemplate严格执行模型 - 视图分离,你不能在模板中放置逻辑,FreeMarker允许你在模板中放入充分的逻辑。这至少在开始时使它更难以使用,但它更多可扩展性。例如,如果您正在生成代码并且模板中没有逻辑,则为另一种语言生成另一个端口不那么繁琐,因为您不必在每个模板中复制逻辑。

There's a paper from Terence Parr that explains the benefits from model-view separation

Terence Parr的论文解释了模型 - 视图分离的好处