You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Ian Dickinson <ia...@hp.com> on 2007/08/09 13:47:39 UTC

Macros will not run

Hi,
I have a template in which all the other VTL directives seem to work 
find, but macros won't run. For example, if I have the following template:

#macro( ijd )
testing 123
#end
#ijd()

it evaluates as:

#ijd()

I've checked that velocimacro.permissions.allow.inline is true, which it 
is. What else should I be checking, or is there some other silly mistake 
I've made?

I'm using Velocity 1.5 with Sun JDK 1.6.0_02

Thanks,
Ian

__________________________________________________________________
Ian Dickinson   HP Labs, Bristol, UK   mailto:ian.dickinson@hp.com
http://www.hpl.hp.com/people/Ian_Dickinson    ph: +44 117 312 8796
Hewlett-Packard Limited              Registered No: 690597 England
Registered Office:            Cain Road, Bracknell, Berks RG12 1HN

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: Macros will not run

Posted by Nathan Bubna <nb...@gmail.com>.
On 8/9/07, Ian Dickinson <ia...@hp.com> wrote:
> I figured it out. Dumb error on my part, though the error message could
> have been a tad more helpful:
>
> > ve.evaluate( pvc, sw, null, reader );
> The template name must not be null, else
> VelocimacroFactory.addVelocimacro barfs.

yeah, i saw that too.  i'm improving the error message right now.  :)

> Ian
>
>
> __________________________________________________________________
> Ian Dickinson   HP Labs, Bristol, UK   mailto:ian.dickinson@hp.com
> http://www.hpl.hp.com/people/Ian_Dickinson    ph: +44 117 312 8796
> Hewlett-Packard Limited              Registered No: 690597 England
> Registered Office:            Cain Road, Bracknell, Berks RG12 1HN
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: Macros will not run

Posted by Ian Dickinson <ia...@hp.com>.
I figured it out. Dumb error on my part, though the error message could 
have been a tad more helpful:

> ve.evaluate( pvc, sw, null, reader );
The template name must not be null, else 
VelocimacroFactory.addVelocimacro barfs.

Ian


__________________________________________________________________
Ian Dickinson   HP Labs, Bristol, UK   mailto:ian.dickinson@hp.com
http://www.hpl.hp.com/people/Ian_Dickinson    ph: +44 117 312 8796
Hewlett-Packard Limited              Registered No: 690597 England
Registered Office:            Cain Road, Bracknell, Berks RG12 1HN

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: Macros will not run

Posted by Ian Dickinson <ia...@hp.com>.
Hi Nathan,
> Do you have any log output for this that we could see?
Yes, attached below.  I've tracked the problem down to a difference in 
the way I'm invoking the engine. I have two test cases, both of which 
read the same template. This one, taken from the user manual, works fine:

VelocityEngine ve = new VelocityEngine();
ve.init();
VelocityContext context = new VelocityContext();

Template template = null;
template = ve.getTemplate(templateName);
StringWriter sw = new StringWriter();
template.merge( context, sw );
log.debug( sw.toString() );


This one, which I use because my templates will in future be dynamically 
generated rather than loaded from a file, doesn't:

StringWriter sw = new StringWriter();
java.io.File f = new java.io.File( templateName );
Reader reader = new FileReader( f );

VelocityEngine ve = new VelocityEngine();
ve.init();
log.debug( "Velocity macro prop: " + ve.getProperty( 
"velocimacro.permissions.allow.inline" ));

VelocityContext pvc = new VelocityContext();
ve.evaluate( pvc, sw, null, reader );
log.debug( sw.toString() );


I can't see a way of creating a Template object from a reader, so from 
reading the API I think I have to call evaluate() directly. However, I 
must presumably be missing a crucial step somewhere.

Any suggestions gratefully received.
Thanks,
Ian

__________________________________________________________________
Ian Dickinson   HP Labs, Bristol, UK   mailto:ian.dickinson@hp.com
http://www.hpl.hp.com/people/Ian_Dickinson    ph: +44 117 312 8796
Hewlett-Packard Limited              Registered No: 690597 England
Registered Office:            Cain Road, Bracknell, Berks RG12 1HN

Re: Macros will not run

Posted by Nathan Bubna <nb...@gmail.com>.
Do you have any log output for this that we could see?

On 8/9/07, Ian Dickinson <ia...@hp.com> wrote:
> Hi,
> I have a template in which all the other VTL directives seem to work
> find, but macros won't run. For example, if I have the following template:
>
> #macro( ijd )
> testing 123
> #end
> #ijd()
>
> it evaluates as:
>
> #ijd()
>
> I've checked that velocimacro.permissions.allow.inline is true, which it
> is. What else should I be checking, or is there some other silly mistake
> I've made?
>
> I'm using Velocity 1.5 with Sun JDK 1.6.0_02
>
> Thanks,
> Ian
>
> __________________________________________________________________
> Ian Dickinson   HP Labs, Bristol, UK   mailto:ian.dickinson@hp.com
> http://www.hpl.hp.com/people/Ian_Dickinson    ph: +44 117 312 8796
> Hewlett-Packard Limited              Registered No: 690597 England
> Registered Office:            Cain Road, Bracknell, Berks RG12 1HN
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org