[
https://issues.apache.org/jira/browse/VELOCITY-680?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12666660#action_12666660
]
Nathan Bubna commented on VELOCITY-680:
---------------------------------------
Yes, that would throw an exception, but that wasn't my example. I created a
value for $map first. I don't see the relevance.
Regarding the complex reference in the LHS, i just tested and found it is
currently immune to the local scope setting just like the proposed #local (or
#global) would be. In this sense, the old #local directive is the most robust
solution available. But, i don't think most people would necessarily expect
that kind of thoroughness, at least not to the point where it would be worth
the greater unwieldiness of the old #local (IMHO).
So, with the precedent for such scope leakage already in place, i suppose that
we might as well not worry about it much in these discussions. If someone does
#local( $map.foo = 'bar' ) and $map is non-local, then $map.foo would become
'bar' globally (and vice-versa for a #global call on a local $map). C'est la
vie.
As for whether #local or #global is more useful, i see your point, but the fact
remains that velocimacro.context.localscope defaults to false, and i would bet
money that a significant majority of users leave it that way (myself included).
So i think #local would be more *frequently* useful. It has certainly been
the more frequently requested feature. Also, thinking of the future, if we
were to enhance #parse to allow parsed templates to have a local scope as well,
then we'd still have to leave them global by default also. Again, #local would
be more frequently useful then.
Of course, maybe this whole idea of #global and #local is less than ideal.
Perhaps we should consider a more extensible solution like #set[scope]( $foo =
'bar' ) where scope is a string identifier for the scope in which the reference
should be set. Then a library like VelocityTools might even create context
implementations that are aware of more than two scopes. I haven't considered
how we'd implement that, of course, it just seems like a more extensible
solution and would of course be a familiar concept to many people from JSP and
the like.
> RFC: New #local directive that behaves like #set but puts things into local
> context in macro rendering
> ------------------------------------------------------------------------------------------------------
>
> Key: VELOCITY-680
> URL: https://issues.apache.org/jira/browse/VELOCITY-680
> Project: Velocity
> Issue Type: New Feature
> Affects Versions: 1.7
> Reporter: Jarkko Viinamäki
> Attachments: velocity-local-directive-1.1.patch,
> velocity-local-directive.patch
>
>
> It would be very useful to be able to set variables that are in local macro
> scope. That is, they do not overwrite "global" variables and are thrown away
> after macro rendering. This would allow people to build macro libraries that
> do not clash so easily with each other.
> There is some implementation of a "LocalDirective" in
> experimental/localdirective but I didn't quite get it and it doesn't follow
> the same syntax as #set. I used a few minutes to hack together this
> alternative implementation which behaves exactly like #set but it puts things
> in local context only.
> There's only one test case since this is Request-for-Comments type of patch.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]