@Nathan
I know that you have good reasons to turn this feature into a no-go. I
appreciate the time you spend for the velocity project and I accept your
decisions even if they may cause some extra work.
@Șergiu
very nice, thank you! It works like a charm.
best regards,
Andreas
Nathan Bubna schrieb:
2011/6/2 Șergiu Dumitriu<[email protected]>:
On 06/02/2011 05:55 PM, Nathan Bubna wrote:
Hi Andreas,
Sorry to have inconvenienced you with this change. The old behavior
was causing problems and had some notable flaws (see my discussion of
the quirks in https://issues.apache.org/jira/browse/VELOCITY-681).
There are no clean workarounds to recover the proxying behavior. You
can set the original reference directly if you know it, of course, but
that could get messy if a variety of references are passed in. You
might also restructure to pass in references to objects or maps so
that changes to the referenced variable are seen in the original
reference when #set on the macro argument reference to that variable.
I know neither of these is ideal.
There is a trick that can be used to achieve the old behavior. I've detailed
the problem here:
http://www.xwiki.org/xwiki/bin/ReleaseNotes/ReleaseNotesXWikiEnterprise30#HMacroevaluationstrategy
The solution is to use #evaluate to set the new value to the original
reference. The loophole that allows this to work is that
"$formalParameterName" expands to "$actualParameterName" when
$formalParameter is undefined/null.
I've written a macro that does this:
https://github.com/xwiki/xwiki-platform/blob/e9051c85ae78fb973f4edbaa968db6bf235eb582/xwiki-platform-core/xwiki-platform-web/src/main/webapp/templates/macros.vm#L1131
You use it by first setting the formal parameter to null, then calling
#setVariable("$formalParameterName" $value).
By the way, will the loophole be preserved in future versions as well, or is
it in danger of being "fixed" at some point?
Oooh. That's a neat trick. I hadn't thought of that. As for the
future, the loophole won't go anywhere in 1.x so long as i'm paying
attention. In 2.0, i thought things were headed toward pass by value
(courtesy of Byron's work/lobbying), but ya'll are welcome to work to
keep the new status quo. I don't think there's a set consensus there,
it's just been them that are doing the work on 2.x making the calls.
Personally, i'm always drawn to support the preferences of those who
are actively contributing, except when i don't. ;-)
Sorry.
On Thu, Jun 2, 2011 at 4:04 AM, Andreas Bohnert<[email protected]> wrote:
hello velocity user list,
from the 1.7 release on we can not change the value of the original
reference of a macro argument anymore.
this is the change log description:
Calling #set on a macro argument (for which a #set-able reference was
passed) will no longer propagate the new value to the original reference,
but merely set the value of the macro argument reference. This was an
obscure, infrequently used feature and was decided to be more problematic
and unpredictable than useful.
so, is there still a way to change the value of the original reference if
I
want to? any workaround?
my knowledge of velocity is limited. I have read this one:
http://wiki.apache.org/velocity/MacroEvaluationStrategy
but I still did not manage to change the value.
any help/example is very much appreciated!!
regards, Andreas
--
Sergiu Dumitriu
http://purl.org/net/sergiu/
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]