hhp 1.0.3

HHP - Haxe Hypertext Preprocessor. PHP-like template system.

Released 2015-10-15.

To install, run:

haxelib install hhp 1.0.3

See using Haxelib in Haxelib documentation for more information.

Current version1.0.3
StatisticsInstalled 302 times
Tags cross, template, web



HHP is a type-safe templating system for Haxe greatly inspired by PHP programming language templating possibilities. HHP stands for Haxe Hypertext Preprocessor.

In PHP you can use plain PHP code inside of a template. This feature gives you unlimited control of template logic. Thanks to macros we can do the same thing with Haxe, but with additional error detection at compile time!


  • Use any valid Haxe code inside templates.
  • Compiler's code completion for variables used in template.
  • Compile-time template parsing, which means you will get compiler notifications if: If you try to pass to template a variable which is not used in template. If you're passing a value of wrong type to a template variable.
  • Include templates in templates.


  1. In a template use tags <?hhp ... ?> to inline Haxe code. Use this.echo(haxe_expression) in inlined code to add haxe_expression value to output buffer.
  2. Use <?=haxe_expression?> to add value of haxe_expression to output buffer.
  3. Use <?hhp this.render('another/template.html', ...); ?> to include another template (see hhp.Template.render() method description)

Base templates path

If you have all your templates in for example path/to/my/views/templates/ you can set this path as base path for all templates using compiler flag:

--macro hhp.Hhp.basePath('path/to/my/views/templates/')

And omit this common path part in templates.


Let's say we have template like this:

<!-- templates/test.html -->
                for (i in 0...this.listSize) {
                    this.echo('<li>Item #${i + 1}</li>');

Notice: inside of a template you must use this to access template variables and methods

Simple way:

var content : String = hhp.Hhp.render('templates/test.html', {
    title : 'Hello, HHP!',
    listSize : 2


Advanced way

class MyTemplate extends hhp.Template {
    * Add template variable declaration if you want to constraint allowed type or
    *   set default value for this variable.
    * If variable used in template is not declared in a class, it will be Dynamic.
    public var listSize : Int = 5;

    * You can also add any additional methods and use them in a template.

class Main {
    static public function main () {
        var tpl = new MyTemplate();
        tpl.listSize = 10; //integer variable
        tpl.| //get code completion with variables: title, listSize

        var content : String = tpl.execute();