title: Freemarker if-else in list (scope)
body: <p>In a list I want to incorporate a if host.machine == 1 then action=Set else action=Create</p>
  
  <p>I want the following output
  <code>Type:Machine;Action:Set;Attributes[Name:machine1~NodeManager.ListenAddress:10.104.17.70~NodeManager.ListenPort:5558]&lt;BR&gt;
      Type:Machine;Action:Create;Attributes[Name:machine2~NodeManager.ListenAddress:10.104.17.71~NodeManager.ListenPort:5558]&lt;BR&gt;</code></p>
  
  <p>My data</p>
  
  <p><code>hosts:[{"name": "trfuoemlpa004v", "node": 0, "server": 1, "Machine": 1, "ManagedPort": "7002", "SSLPort": 1081},
         {"name": "trfuoemlpa007v", "node": 1, "server": 2, "Machine": 2, "ManagedPort": "7002", "SSLPort": 1081}]</code></p>
  
  <p>I have made different templates all fails:</p>
  
  <p>1)
  <code>&lt;#list hosts as host&gt;&lt;#assign machine=${host.machine}&gt;&lt;#if machine == 1&gt;&lt;#assign action="Set"&gt;&lt;#else&gt;&lt;#assign action="Create"&gt;&lt;/#if&gt;Type:Machine;Action:${action};Attributes[Name:${host.machine}~NodeManager.ListenAddress:${host.name}~NodeManager.ListenPort:${nodeManagerPort}]&lt;BR&gt;&lt;/#list&gt;</code></p>
  
  <p><code>**freemarker.core.ParseException: Encountered "}" at line 8, column 40 in
  J2EE.properties.
  Was expecting one of:"&gt;" ...
      "." ...
      "[" ...
      "(" ...
      "?" ...
      "!" ...
      &lt;TERMINATING_EXCLAM&gt; ...
      "??" ...
      "+" ...**</code></p>
  
  <p>2)
  <code>&lt;#list hosts as host&gt;&lt;#if host.machine == 1&gt;&lt;#assign action="Set"&gt;&lt;#else&gt;&lt;#assign action="Create"&gt;&lt;/#if&gt;Type:Machine;Action:${action};Attributes[Name:${host.machine}~NodeManager.ListenAddress:${host.name}~NodeManager.ListenPort:${nodeManagerPort}]&lt;BR&gt;&lt;/#list&gt;</code></p>
  
  <p><code>**freemarker.core.InvalidReferenceException: Expression host.machine is undefined**</code></p>
  
  <p>3)
  <code>&lt;#list hosts as host&gt;&lt;#if $host.machine} == 1 &gt; ...</code></p>
  
  <p><code>**freemarker.core.ParseException: Encountered "}" at line 8, column 40 in
  J2EE.properties.
  Was expecting one of:"&gt;" ...
      "." ...
      "[" ...
      "(" ...
      "?" ...
      "!" ...
      &lt;TERMINATING_EXCLAM&gt; ...
      "??" ...
      "+" ...**</code></p>