Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XWIKI-22152 In velocity, can't use $macro.myVar with setVariable macro #3108

Merged
merged 2 commits into from
May 15, 2024

Conversation

Josue-T
Copy link
Contributor

@Josue-T Josue-T commented May 7, 2024

Jira URL

https://jira.xwiki.org/browse/XWIKI-22152

Changes

Description

Add support for variable like $macro.myvar in setVariable velocity macro.

Clarifications

So to fix the described issue, the idea is to improve the setVariable macro to be able to set correctly the value when the caller pass a parameter to set with something like this $macro.xxx.

For this we need the $macro.parent which give access to the $macro dict of the caller. Note that we need to call $macro.parent.parent because $macro.parent return the macro which is calling setVariable and so we want to call the parent of this one.

Executed Tests

To test this we can use this small code

#macro(myChildMacro $return)
  #set($return = $NULL)
  #setVariable("$return" "my new value")
#end

#macro(myParentMacro)
  #myChildMacro($macro.childResult)
  $macro.childResult
#end

#myParentMacro()

Before we have this result

$macro.childResult

After we have this result:

my new value

Expected merging strategy

  • Prefers squash: Yes
  • Backport on branches: Not needed, as it's a new feature.

@tmortagne
Copy link
Member

tmortagne commented May 13, 2024

* In velocity, add support for $macro.myVar in setVariable macro
@Josue-T
Copy link
Contributor Author

Josue-T commented May 14, 2024

Would be very interesting to start adding some unit tests for this vmacro in https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-web/xwiki-platform-web-templates/src/test/java/org/xwiki/web/MacrosTest.java.

Thanks for the feedback. I added some unit test for this.

@tmortagne tmortagne merged commit 933bd59 into xwiki:master May 15, 2024
1 check passed
@Josue-T Josue-T deleted the XWIKI-22152 branch May 15, 2024 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants