title: FreeMarker Transporting Lists
body: <p>In one of my FreeMarker templates I have a pair of macros which look something like this</p>
  
  <pre><code>&lt;#macro RepeatTwice&gt;&lt;#nested 1&gt;&lt;#nested 2&gt;&lt;/#macro&gt;
  
  &lt;#macro Destinations&gt;
  &lt;#assign DestinationList = []&gt;
  &lt;@RepeatTwice ; Index&gt;
  &lt;#assign City == some XPath expression dependant on the index&gt;
  &lt;#if City == something&gt;
  &lt;#assign DestinationList = DestinationList + ["some string"]&gt;
  &lt;#elseif City == something else&gt;
  &lt;#assign DestinationList = DestinationList + ["some string"]&gt;
  &lt;/#if&gt;
  &lt;/@&gt;
  &lt;/#macro&gt;
  </code></pre>
  
  <p>So now, my destination list contains 2 values. This works in that if I insert <code>${DestinationList[0]}</code> or <code>${DestinationList[1]}</code> before <code>&lt;/#macro&gt;</code> I get the expected output.</p>
  
  <p>My question is --- in a separate template I would like to capture the whole of the list from this macro so that I can access its elements as and when I need them.</p>
  
  <p>For this I need the macro to return the whole list, not just an element from it.</p>
  
  <p>But inserting <code>${DestinationList}</code> or just DestinationList returns an error. </p>
  
  <p>I have tried doing things like <code>${DestinationList[0,1]}</code> and the like but nothing seems to work. </p>
  
  <p>Is this possible? </p>
  
  <p>Thanks,</p>
  
  <p>Basil</p>