title: looping a template using groovy GStringTemplateEngine()
body: <p>My requirement is to <strong>create a template engine to support a looping in it</strong>.</p>
  
  <p>The <strong>final template</strong> should look something like this:</p>
  
  <pre><code>#cat output.template 
  env:
    - name : param1 
      value : 1
    - name : param2 
      value : 2
  </code></pre>
  
  <p>I have <strong>pseudo code to explain my requirement</strong></p>
  
  <pre><code>def f = new File('output.template')
  def engine = new groovy.text.GStringTemplateEngine()
  
  def mapping = [
      [ name : "param1",
        value : "1"],
      [ name : "param2",
        value : "2" ]
  ] // This mapping can consists of a multiple key value pairs.
  
  def Template = engine.createTemplate(f).make(mapping) 
  
  println "${Template}"
  </code></pre>
  
  <p>Can someone help me <strong>how to achieve this requirement of looping inside the templates and how should I modify my template?</strong></p>
  
  <p><strong>*UPDATE : All the solutions provided by <em></strong><code>tim_yates</code><strong></em> or by <em></strong><code>Eduardo Melzer</code><strong></em> has resulted in following output with extra blank lines at the end of template. What could be the reason for that?*</strong> Are the solution providers not able to see this behavior or the issue is my system only?.</p>
  
  <pre><code># groovy loop_template.groovy 
  env:
    - name: param1
      value : 1 
    - name: param2
      value : 2 
  
  
  root@instance-1:
  </code></pre>