1

I would like to product php code within HTML with heXa. For example:

<?php
$temp = 'Hello';
?>
<html>
<body>
<?php echo $temp?>
</body>
</html>

How would I write the above using haxe? The haxe site shows you how to produce PHP code, but it doesn't mention how to produce PHP with HTML.

rexposadas
  • 3,109
  • 3
  • 27
  • 49

1 Answers1

8

Haxe isn't a scripting language that can be called from within a html file in that way. You have to adapt a workflow where you prepare your html templates and your data as separate units and let the compiled application combine them according to your wishes.

Here's a quick example that should work in any Haxe server target language (php, neko, cpp). (Maybe also java and c# - not sure if the Template implementation is ready) :

package ;

import haxe.Template;
import neko.Lib;

class Main 
{
    static function main() 
    {
        var data = { greeting: 'Hello' };       
        var template = new Template('<html><body>::greeting::</body></html>');      

        var output = template.execute(data);
        Sys.print(output);      
    }   
}

There are a bunch of template engines for Haxe out there, for example the .NET Razor clone Erazor

Cambiata
  • 3,705
  • 9
  • 35
  • 45
  • Thank you. Other than being a noob question, I do not know why I received the down votes. I wish those who down-voted left a message. That aside, I appreciate the help. – rexposadas Nov 27 '12 at 00:56
  • @rexposadas See here: http://stackoverflow.com/questions/15286331/run-php-client-side – Anderson Green Mar 13 '13 at 03:31
  • @rexposadas I don't know either - I upvoted the question. It is a good to know when you are coming from PHP to Haxe that you need to use templates. – AturSams May 11 '14 at 18:06