Time for action – Creating our template

Now, let's create a template that will simply take an object with the property posts to hold our list of posts.

Add this code to your template.html file:

<html>
   <head>
      <title>List of Posts</title>
   </head>
   <body>
      <!-- Simply display a greeting -->
      <h1>Hi and welcome on my blog!</h1>
      <!-- Iterate over all Posts -->
      ::foreach posts::
         <!-- Display's the blog post's title -->
         <h2>::title::</h2>
         <!-- Display's the blog post's body -->
         <div>::body::</div>
      ::end::
   </body>
</html>

You will also want to include this file as a resource named template.

To do so, just add the following to your compilation command:

-resource template.html@template

That's all it takes.

Get haXe 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.