ANT Task for using html-template’s index.template.html

Posted on July 31, 2007 | 10 comments

I am constantly changing the default index.template.html in my Flex projects. This is quite nice, as you can even change the index.template.html to index.template.php and it will generate the file correctly. But in most cases I have ANT builds on the servers that do all the building. This is where I found the Flex ANT html-wrapper task falling short.

The Flex ANT html-wrapper task does not let you use custom/modified template files. But don’t worry its actually quite easy to do this in ANT, as its just a bunch of token substitution. Here is one way to accomplish the task (I was having issues with filterchain and replacetokens):

<copy file="${app.base.dir}/html-template/index.template.html"
                 tofile="${app.webroot.dir}/MyApp.html" />
<replace file="${app.webroot.dir}/MyApp.html" token="$${swf}" value="MyApp"/>
<replace file="${app.webroot.dir}/MyApp.html" token="$${width}" value="600"/>
<replace file="${app.webroot.dir}/MyApp.html" token="$${height}" value="600"/>
<replace file="${app.webroot.dir}/MyApp.html" token="$${bgcolor}" value="#000000"/>
<replace file="${app.webroot.dir}/MyApp.html" token="$${application}" value="MyApp"/>
<replace file="${app.webroot.dir}/MyApp.html" token="$${version_major}" value="9"/>
<replace file="${app.webroot.dir}/MyApp.html" token="$${version_minor}" value="0"/>
<replace file="${app.webroot.dir}/MyApp.html" token="$${version_revision}" value="28"/>
  • Dan G. Switzer, II

    Have you been able to configure your ANT scripts to automatically run on save?

    Mine seem to require that I manually trigger the ANT scripts.

    Any tips?

  • Renaun Erickson

    No any pre/post compile firing of other programs is not possible yet. We should ask for this feature with the Flex Builder.

  • David Coletta

    There’s another way to do this, if I’m understanding your post. (This is via Mike Morearty.) The filename for the main index.template.html file is hard-coded to that filename. But the contents of that file are under your control — it gets that file from the appropriate subdirectory of /resources/html-templates.

  • Renaun Erickson


    Yes you are right, I modify the index.template.html all the time. You can actually add other Xxxx.template.html to the folder and Flex Builder will replace them too. But this post is for the build servers that do not use Flex Builder and need to output the templates, and I wanted to keep the same template for development and build scripts.

  • David Coletta

    OK, that makes sense.

  • Pingback: RIA pedia - Rich Internet Applications - Its all about the user experience!

  • Brian Thornton

    Any idea where you can find a complete list of the vars that by defauly are found in index.template.html?

  • Brian Thornton

    Also keep in mind when changing it

    That changing extension mean changing the project properties..

  • Renaun Erickson

    don’t know of the complete list that are defaults of the Flex Project

  • Pingback: Continuous Build: Flex Builder 3 vs Visual Studio 2008 « Tales from a Trading Desk

  • L. , Brussels

    thanks, this was helpful

  • Pingback: Flex: Custom HTML Wrappers In Ant | Chasing Daydreams

  • http://none Moussa

    thanks, this was helpful