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.
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. That way I won't have to write long strings of HTML code in a .php file.
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. I find {$myvar}
to be more readable than <?php echo $myvar; ?>
.
Long strings of HTML code shouldn't be needed, as PHP is a template language anyway. End PHP context with ?>
then use <?php echo $myvar; ?>
embedded in your HTML where necessary. Make your email templates separate PHP files and include them to make the template solution complete.
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). This has been discussed at length on Stack Overflow. One good discussion is here:
- https://stackoverflow.com/q/62605/14329
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.
I recommend, Twig - one of the fastest, simple & secure PHP template engine.
See this link talks about performance of Twig with other PHP template-engines.
BTW, Twig is developed by the folks who created Symfony :-).
精彩评论