Create dependency templates

Hi,

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.

2 Likes

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

2 Likes

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.

3 Likes

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