Using foreach in Haxe Templates

I am having trouble finding a solution to a problem when using the foreach loop in Haxe Templates. I am using the following code to produce a HTML form from a given input:

public function execute(outputString:String)
        var result = "";
        var data:ElementData = { elements: new Array<String>() };

        for (e in elements)
            var value = types.get(;

        for (e in data.elements)

        var t = new Template(outputString);
        result = t.execute(data);

        return result;

Using this code, with the following input:

auto "ID"
text "Title"

I get the output from the trace calls above as:

Parser.hx:122: <input type="text" readonly="true" name="ID" />
Parser.hx:122: <input type="text" name="Title" />

I know from this that the input is correctly being parsed.

I use the following Main.hx to get all this:

class Main

    public static function main()
        var p = new Parser("examples/simple/script.form");
        p.types.set("auto", parse_auto);
        p.types.set("text", parse_text);
        var result = p.execute("examples/simple/basic.html"));

    static function parse_auto(d:Element):String
        var result = '<input type="text" readonly="true" name="${d.title}" />';
        return result;

    static function parse_text(d:Element):String
        var result = '<input type="text" name="${d.title}" />';
        return result;


And in basic.html I have the following:

<!DOCTYPE html>

        ::foreach elements::


Just very simple, to get things working. However, when trying to use this file with the p.execute call, I get the following error:

Called from ? line 1
Called from Main.hx line 16
Called from Parser.hx line 124
Called from C:\HaxeToolkit\haxe\std/haxe/Template.hx line 110
Called from C:\HaxeToolkit\haxe\std/haxe/Template.hx line 369
Called from C:\HaxeToolkit\haxe\std/haxe/Template.hx line 385
Called from C:\HaxeToolkit\haxe\std/haxe/Template.hx line 369
Called from C:\HaxeToolkit\haxe\std/haxe/Template.hx line 356
Called from C:\HaxeToolkit\haxe\std/haxe/Template.hx line 120
Called from C:\HaxeToolkit\haxe\std/neko/_std/Reflect.hx line 25
Uncaught exception - Invalid field access : __s

I don’t understand why this is happening, because the array elements in the data variable passed into the template is initialised, and I have double-checked that the array actually has data stored in there, as seen above. So my question is how can the Template system not pick this up?

Any help would be great!

What version of Haxe are you using? We had a problem with Haxe 3.3-RC, and had to include a patched copy of haxe.Template to get it to work. Perhaps its the same problem?

Yeah, I’m actually using 3.3. I’ll upgrade and see if that makes a difference.

Or you could try this file in your local source path:

That’s what fixed Template for us