Use velocity macro from a different template

7 Views Asked by At

I have a usecase where I have existing velocity templates having rendering content as well as few macros defined. Now I want to find a way to just invoke the macro from outside the template and get the content from the macro.

I have explored below options but didn't help:

  1. Use #parse but this will eventually parse the complete template and render. So, can't use this.
  2. Saw this option org.apache.velocity.Template.getMacros(). I thought once I load the main template in Template class, I could get the macro from getMacros() method. But this always seem to return null. Not sure what this is for.
  3. One option which should work is to parse the complete template and fetch the macro definition string and use that. But this doesn't seem to be a safe option considering cases like possibility of commented code, macro overloading etc. So, didn't want to use this.

Is there a way I can achieve that?

0

There are 0 best solutions below