Hello, I wrote a Content Macro that accepts two parameters an array of Document References and an array of strings. Now I tried using the built in org.xwiki.model.reference.DocumentReference type for my parameter and it does show the PagePicker in the editor however, I can not select multiple pages. I also tried using java.util.List<org.xwiki.model.reference.DocumentReference> logically that makes sense because it is storing a list of DocumentReference’s however I get no picker at that point. I also can not find any documentation on implementing a custom PagePicker.
Hi,
You need to:
- use
java.util.List<org.xwiki.model.reference.DocumentReference>as the parameter type (as you tried) - create the
/templates/html_displayer/java.util.list(org.xwiki.model.reference.documentreference)/edit.vmtemplate (where XWiki was deployed) with the following content:#set ($parameters = {}) #set ($discard = $parameters.putAll($displayer.parameters)) #set ($parameters.value = $displayer.value) #set ($parameters.multiple = true) #pagePicker($parameters) - restart XWiki
If you need a custom picker, then best is to create a dedicate Java type for your macro parameter and then write the corresponding Velocity template (use the simple name of the Java class, lower cased, in the path). Check the other templates in /templates/html_displayer/* for inspiration.
Hope this helps,
Marius
That fixed my issue however, for some reason the selected pages are separated by space instead of comma once I actually get them in the Macro code. In the page source code where I use the macro looks like this for the actorPageLink which looks correct.
{{hello actorPageLink="Shows.Actors.Force Jiratchapong Srisang.WebHome,Shows.Actors.Leo Saussay.WebHome" role="James,Jim"/}}
This is what the macro code looks like
{{velocity}}
#set ($targetSyntaxId = $wikimacro.context.transformationContext.targetSyntax.type.id)
#if ($wikimacro.parameters.actorPageLink && !$wikimacro.parameters.actorPageLink.isEmpty() && $wikimacro.parameters.role && !$wikimacro.parameters.role.isEmpty())
$wikimacro.parameters.actorPageLink
#end
{{/velocity}}
Back onto the page for the output I get the following array
[xwiki:Shows.Actors.Force, xwiki:Main.Jiratchapong, xwiki:Srisang.WebHome, xwiki:Shows.Actors.Leo, xwiki:Saussay.WebHome]
It should be
["Shows.Actors.Force Jiratchapong Srisang.WebHome","Shows.Actors.Leo Saussay.WebHome"]
For some reason the parameter seems to be interperted before I even access inside of the Macro code which is causing it to get separated into separate page links. I tried to look at the Pagepicker widget page for more info but I can not find anything to prevent that.
Thank you for your help
I am not for sure if this is the correct way of doing this however if i use the following inside of my macro code.
$xcontext.macro.params.actorPageLink
I will get the raw string value instead of what xwiki thinks it should be. This prevents xwiki from creating DocumentReferences that don’t exist when separating based on the space. However according to WikiMacroStore the $xcontext.macro should be considered deprecated.
Side note: The values that you get back from $wikimacro.parameters.actorPageLink is not a String, but a list of document references (as the type says: java.util.List<org.xwiki.model.reference.DocumentReference> ), so you can unloop instead as e.g.
#if ($wikimacro.parameters.actorPageLink && !$wikimacro.parameters.actorPageLink.isEmpty() && $wikimacro.parameters.role && !$wikimacro.parameters.role.isEmpty())
#foreach($actorPageLink in $wikimacro.parameters.actorPageLink)
* $actorPageLink
#end
#end
(or instead if writing out the string representation do something else like $actorPage = $xwiki.getDocument($actorPageLink) etc.)