简体   繁体   English

Apache 速度与 PHP

[英]Apache Velocity with PHP

I've been searching Google to try and find if Apache Velocity can be used with PHP but so far I haven't found anything that says it can.我一直在搜索 Google 以尝试查找 Apache Velocity 是否可以与 PHP 一起使用,但到目前为止我还没有找到任何可以说明的东西。

Does anyone know if this is possible or if there is an alternative method.有谁知道这是否可能或是否有替代方法。

Basically what I'm trying to do is separate HTML emails out of my PHP code so that I can just have a load of template files and then fire them off when needed.基本上我要做的是将 HTML 电子邮件从我的 PHP 代码中分离出来,这样我就可以加载大量模板文件,然后在需要时将它们关闭。 That way I won't have to write long strings of HTML code in a.php file.这样我就不必在 .php 文件中编写长字符串 HTML 代码。

Any help would be greatly appreciated.任何帮助将不胜感激。

For PHP I am using Smarty templating engine, it has a similar syntax to Velocity and is easy to use.对于 PHP,我使用Smarty模板引擎,它的语法与 Velocity 相似,易于使用。 I find {$myvar} to be more readable than <?php echo $myvar; ?>我发现{$myvar}<?php echo $myvar; ?>更易读。 <?php echo $myvar; ?> . <?php echo $myvar; ?> .

Long strings of HTML code shouldn't be needed, as PHP is a template language anyway.不需要长字符串 HTML 代码,因为 PHP 无论如何都是模板语言。 End PHP context with ?> then use <?php echo $myvar; ?>?>结束 PHP 上下文,然后使用<?php echo $myvar; ?> <?php echo $myvar; ?> embedded in your HTML where necessary. <?php echo $myvar; ?>必要时嵌入到您的 HTML 中。 Make your email templates separate PHP files and include them to make the template solution complete.使您的 email 模板分离 PHP 文件并包含它们以使模板解决方案完整。

There are other PHP-based template solutions as well, so no need to look to Velocity (which positions itself as an alternative to PHP right on its overview page ).还有其他基于 PHP 的模板解决方案,因此无需关注 Velocity(它在其概述页面上将自己定位为 PHP 的替代品)。 This has been discussed at length on Stack Overflow.这已在 Stack Overflow 上进行了详细讨论。 One good discussion is here:这里有一个很好的讨论:

I don't see it either or couldn't find a way to include.我也没有看到或找不到包含的方法。 BTW, Velocity template is more Java based and it is widely used for Java coding, you should be looking for Twig, Smarty, etc PHP based template engine system. BTW, Velocity template is more Java based and it is widely used for Java coding, you should be looking for Twig, Smarty, etc PHP based template engine system.

I recommend, Twig - one of the fastest, simple & secure PHP template engine.我推荐Twig - 最快、简单和安全的 PHP 模板引擎之一。

See this link talks about performance of Twig with other PHP template-engines.请参阅此链接讨论 Twig 与其他 PHP 模板引擎的性能。

BTW, Twig is developed by the folks who created Symfony:-).顺便说一句,Twig 是由创建 Symfony 的人开发的:-)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM