You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Anton Tonchev <to...@xi-tec.com> on 2006/08/28 14:52:28 UTC

Are inline macros cached somewhere?

Hello!

I have the following problem:

I have two pages userRequests.vm and vendorRequests.vm.

The first one has userRequests.vm:
#macro( requestItemActions $requestId )
        <user specific actions>
#end
#parse("includes/requestView.vm")
-----------------

And the second one vendorRequests.vm:
#macro( requestItemActions $requestId )
        <vendor specific actions>
#end
#parse("includes/requestView.vm")
------------------

The file that is included (includes/requestView.vm) contains an
interation over some items and calls the macro requestItemActions for
each item.

The problem is that the inline defined macro is somewhat cached
because after the first parse of the temlate it is remambered and in
both pages (vendorRequest.vm and userRequest.vm) is used the same
template.

Do you have any idea why it is not working?

I tried with the
velocimacro.permissions.allowInlineToOverride=true
but it still isn't working.

Thanks in advance.


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


Re: Are inline macros cached somewhere?

Posted by Nathan Bubna <nb...@gmail.com>.
Limiting yourself to just one velocimacro for both situations isn't a
bad idea.  :)

You might also try these settings:

velocimacro.permissions.allow.inline = true
velocimacro.permissions.allow.inline.to.replace.global = false
velocimacro.permissions.allow.inline.local.scope = true

I believe that will keep your #requestItemActions macro local to their
defining templates, but i think (not 100% sure at the moment) the
mechanics of #parse means the macro will also be available to
templates parsed by the template that defines #requestItemActions.  If
not, then try this:

velocimacro.permissions.allow.inline = true
velocimacro.permissions.allow.inline.to.replace.global = true
velocimacro.permissions.allow.inline.local.scope = false

This is inefficient and not really recommended, since it keeps
replacing the global #requestItemActions every time, but i think it
should also work.

Read more on these at
http://jakarta.apache.org/velocity/docs/developer-guide.html#Velocity%20Configuration%20Keys%20and%20Values


On 8/28/06, Matthias Hendler <ma...@siv.de> wrote:
> Hello,
>
> I think that in velocity all macros have a global scope.
> So whenever you define a macro it will by put in this global area. And I
> would expect that velocity doesn't parse an "already known" macro twice
> for performance reasons.
>
> What can you do?
> Define one macro with a second parameter to determine the scope
> (user/vendor).
> Before the parse you set a global variable which helds the actual scope.
> In your RequestView you call the macro with this global variable.
> Define a macro like:
>
> #macro( requestAction $id $scope )
> #if ("user".equals($scope)
>         <user actions>
> #else
>         <vendor actions>
> #end
> #end
>
>
> In your user view:
> #set ($GlobalActualScope = "user")
> #parse("includes/requestView.vm")
>
> In your requestView call the macro like:
> requestAction $actualId $GlobalActualScope
>
>
> Waiting for an expert what he says. ;-)
> Matthias
>
>
>
> Anton Tonchev schrieb:
>
> >Hello!
> >
> >I have the following problem:
> >
> >I have two pages userRequests.vm and vendorRequests.vm.
> >
> >The first one has userRequests.vm:
> >#macro( requestItemActions $requestId )
> >        <user specific actions>
> >#end
> >#parse("includes/requestView.vm")
> >-----------------
> >
> >And the second one vendorRequests.vm:
> >#macro( requestItemActions $requestId )
> >        <vendor specific actions>
> >#end
> >#parse("includes/requestView.vm")
> >------------------
> >
> >The file that is included (includes/requestView.vm) contains an
> >interation over some items and calls the macro requestItemActions for
> >each item.
> >
> >The problem is that the inline defined macro is somewhat cached
> >because after the first parse of the temlate it is remambered and in
> >both pages (vendorRequest.vm and userRequest.vm) is used the same
> >template.
> >
> >Do you have any idea why it is not working?
> >
> >I tried with the
> >velocimacro.permissions.allowInlineToOverride=true
> >but it still isn't working.
> >
> >Thanks in advance.
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> >
> >
> >
>
>
> --
> Mit freundlichen Grüßen
>
> Matthias Hendler
>
> Technologie
>
> SIV.AG
> Konrad-Zuse-Str. 1
> 18184 Roggentin
>
> Telefon: +49 (0)3 81 / 25 24 - 0
> Telefax: +49 (0)3 81 / 25 24 - 4 99
>
>
>
>
> mailto:matthias.hendler@siv.de
> http://www.siv.de
>
>
>
> **********************************************************************
> This email and any files transmitted with it are confidential
> and intended solely for the use of the individual or entity
> to whom they are addressed. The views expressed in this
> e-mail are those of the individual author and not necessarily
> those of SIV.AG.
>
> This footnote also confirms that this email message has
> been swept by serval anti-virus tools for the presence
> of computer viruses.
> *********************************************************************
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

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


Re: Are inline macros cached somewhere?

Posted by Matthias Hendler <ma...@siv.de>.
Hello,

I think that in velocity all macros have a global scope.
So whenever you define a macro it will by put in this global area. And I 
would expect that velocity doesn't parse an "already known" macro twice 
for performance reasons.

What can you do?
Define one macro with a second parameter to determine the scope 
(user/vendor).
Before the parse you set a global variable which helds the actual scope.
In your RequestView you call the macro with this global variable.
Define a macro like:

#macro( requestAction $id $scope )
#if ("user".equals($scope)
	<user actions>
#else
	<vendor actions>
#end
#end


In your user view:
#set ($GlobalActualScope = "user")
#parse("includes/requestView.vm")

In your requestView call the macro like:
requestAction $actualId $GlobalActualScope


Waiting for an expert what he says. ;-)
Matthias



Anton Tonchev schrieb:

>Hello!
>
>I have the following problem:
>
>I have two pages userRequests.vm and vendorRequests.vm.
>
>The first one has userRequests.vm:
>#macro( requestItemActions $requestId )
>        <user specific actions>
>#end
>#parse("includes/requestView.vm")
>-----------------
>
>And the second one vendorRequests.vm:
>#macro( requestItemActions $requestId )
>        <vendor specific actions>
>#end
>#parse("includes/requestView.vm")
>------------------
>
>The file that is included (includes/requestView.vm) contains an
>interation over some items and calls the macro requestItemActions for
>each item.
>
>The problem is that the inline defined macro is somewhat cached
>because after the first parse of the temlate it is remambered and in
>both pages (vendorRequest.vm and userRequest.vm) is used the same
>template.
>
>Do you have any idea why it is not working?
>
>I tried with the
>velocimacro.permissions.allowInlineToOverride=true
>but it still isn't working.
>
>Thanks in advance.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>  
>


-- 
Mit freundlichen Grüßen

Matthias Hendler

Technologie

SIV.AG
Konrad-Zuse-Str. 1
18184 Roggentin

Telefon: +49 (0)3 81 / 25 24 - 0
Telefax: +49 (0)3 81 / 25 24 - 4 99




mailto:matthias.hendler@siv.de
http://www.siv.de



**********************************************************************
This email and any files transmitted with it are confidential
and intended solely for the use of the individual or entity
to whom they are addressed. The views expressed in this
e-mail are those of the individual author and not necessarily
those of SIV.AG.

This footnote also confirms that this email message has
been swept by serval anti-virus tools for the presence
of computer viruses.
*********************************************************************




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