Using Handlebars template files in your app

You can use any templating engine you like in a Zendesk v2 app. A popular choice is Handlebars.

The simplest way to create a Handlebars template is to include the markup in <script> tags in the main HTML file. The template markup looks as follows in an iframe.html file:

<script id="my-template" type="text/x-handlebars-template">    <p>Hello, world!</p></script>

For an example, see Creating and inserting templates in the introductory tutorial series.

However, for anything except simple apps, this approach can quickly make your iframe file bloated.

Another option is to store the markup in separate .hdbs files in the assets folder, then compile them at runtime. To learn how, see the following Gist by Daniel Pawluk, Developer Relations Manager at Zendesk. Note that the template output will appear in the <div id="view_container"></div> tag in the iframe.html file.

Note: You can also precompile templates, but that's beyond the scope of this article. For more information, see How to Precompile Handlebars Templates.