title: Velocity template dynamic reference value modification from Java code
body: <p>I need to replace references (properties and methods) in the Velocity
  templates to some other values during template rendering.
  For example, from the template below:</p>
  
  <pre><code>___
  I have $some text $daisy
  #foreach ($someElement in $someCollection)
    #$someElement.doSomething()
  #end
  ___
  </code></pre>
  
  <p>I need to get such text:</p>
  
  <pre><code>___
  I have lalala1 text lalala1
  lalala2
  lalala2
  lalala2
  ___
  </code></pre>
  
  <p>Besides, the reason is I don't know the names of references and the
  amount of them beforehand.</p>
  
  <p>Well, technically, indeed I can open templates and manually look through, but I want to escape this way.</p>
  
  <p>First of all, I tried to get references names from the template,
  working with implementation of ReferenceInsertionEventHandler, but the
  problem was in directives.</p>
  
  <p>For example, with foreach I had exception "Could not determine type of
  iterator in #foreach loop"
  I looked through the velocity source code, I can change it as I need,
  but it will kill future project maintainability.</p>
  
  <p>So the question is:
  is there any way to get all references names (properties and methods)
  from template and to change the values of them during rendering?</p>