3

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.

diggersworld
  • 12,770
  • 24
  • 84
  • 119
  • Apache Velocity is written as a Java Template Engine, I think it would be very hard to integrate with PHP, :-) – khotyn Aug 11 '11 at 13:19

3 Answers3

6

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; ?>.

serg
  • 109,619
  • 77
  • 317
  • 330
2

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:

Community
  • 1
  • 1
Nicole
  • 32,841
  • 11
  • 75
  • 101
  • I'm using Kohana. So what I've done is created a view with the HTML email in. Then I just send a render of that view to my email service (Amazon SES). – diggersworld Jul 18 '11 at 13:10
0

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 :-).

Rakesh Sankar
  • 9,337
  • 4
  • 41
  • 66