Overriding a macro definition

Christopher Schultz <[email protected]> Mon, 20 Jun 2022 13:40:08 -0400
Newsgroups gmane.comp.jakarta.velocity.user
Message-ID <[email protected]>
All,

I have a process where I'd like to use a global macro library but also 
allow the individual templates to override the macros if necessary.

My code looks something like this:


// == One-time setup
Properties props = new Properties();
properties.setProperty("velocimacro.inline.allow", "true");
props.setProperty("velocimacro.inline.local_scope", "true");
VelocityEngine ve = new VelocityEngine();
ve.init(props);

VelocityContext globalContext = new VelocityContext();

// Load the global macro template
engine.evaluate(globalContext, new NullWriter(), "VM_global_library", 
new InputStreamReader(...));

// == for each template to be evaluated
VelocityContext ctx = new VelocityContext(globalContext);

StringWriter sw = new StringWriter();
engine.evaluate(context, sw, "foobar", templateString);

What I'm finding is that any macro defined in the "global library" can't 
be overridden in the individual template... I still get the global 
definition. I know my local definition is "correct" because if I change 
the name of the global macro, the local one runs as expected.

What am I missing, here?

I know this works in my web-based projects where I'm using 
VelocityLayoutServlet which does something similar. Do I need to 
explicitly-declare some things as "global" or establish scopes in a way 
I'm not doing above?

Thanks,
-chris