Create dependency templates


Let say that I have some dependency files, xml or whatever and I would like to transform it into templates, like the template.html but for different purpose. How can I do that? Should I use macro? Ideally, I would like to control the content of the template from project.xml.


It depends on the target, but for HTML5, iOS and Android, there is a “template” directory (like “html/template/index.html”) where everything in that template path is copied. For example, on Android, I believe you could add a new file (which is processed as a template) by adding “android/template/myfile.xml” to your own template directory


Yes, indeed if I add any custom file with the following expression ::APP_TITLE::, it works. But now, how can I add my own custom expression, e.g: ::myCustom:: ? Where can I set the value of myCustom, can I add it in project.xml?

In project.xml:

<set name="myCustom" value="hello world" />

In your template:

cout << "::SET_myCustom::";

You can also use <haxedef />, in which case the template variable would be DEFINE_myCustom. There aren’t any other prefixes available, but those two should be enough.


Awesome! It works great! Thanks.

1 Like

This is absolutely smurftastic!
This helped me immensely. I should mention that per that link about prefixes, these defines get converted to uppercase. That may have not been the case two years ago. So if your project.xml has a define like <haxedef name="specialMode" /> it will be accessed as ::DEFINE_SPECIALMODE:: in the template. See also the documentation for project XML files.

Oh yeah, that’s new since then. Note that formatUppercaseVariable() is more advanced than toUppercase() - it detects words and places underscores between them. That means <haxedef name="specialMode" /> would become ::DEFINE_SPECIAL_MODE::.

I am now wanting to give my template some more data to process. For example, the default template has:

::if linkedLibraries::::foreach (linkedLibraries)::
	<script type="text/javascript" src="::__current__::"></script>::end::::end::

In my case, I am wanting to create a macro that calculates what text files to include and then inserts them into the template as SEO text. I am renaming the index.html to index.php, so my end template would be something like:

::if myFiles::
::foreach (myFiles)::
<?php include('::__current__::'); ?>

Any ideas about that? Specifically, how do I make additional data available to the template when it is processed?