On Thu, Nov 24, 2016 at 2:28 PM, Pascal BASTIEN <pbasnews-xwiki@yahoo.fr> wrote:
I use this methods,
hasParent(EntityReference expectedParent) and i noticed that
I can not use string to set EntityReference.
Then i must use this before: "#set ($reference =
$services.model.resolveSpace('xwiki:Encyclopédie'))"
and "$doc.documentReference.hasParent($reference)" because
$doc.documentReference.hasParent('xwiki:Encyclopédie')
doesn't work.
Am I right? Anyway, I can understand that.
There is one magic thing about Velocity in XWiki that you need to keep in mind: it automatically convert parameters to the right type (when there is a converter provided for that type).
For example the converter for the type
EntityReference understand the
following
syntax: [<entitytype>:]<entityreference> (the default entity type is "document" if you don't provide it) so the space with reference "xwiki:Encyclopédie" will be the string
"space:xwiki:Encyclopédie" as in
hasParent('space:xwiki:Encyclopédie').
Right :-) $doc.documentReference.hasParent('space:xwiki:Encyclopédie') work well but I don't understand why we must use "xwiki" in space name.
You don't have to use "xwiki". "xwiki" is is the wiki in which the space is located, if you want the space "Encyclopédie" in the current wiki then just don't put the wiki as in $doc.documentReference.hasParent('space:Encyclopédie'). Keep it mind that we are talking about the space reference here, not the space name.
Heu .... it is not the same?
Then maybe I found an issue because without "xwiki:" documentReference.hasParent doesn't work: On jetty package 8.4: I paste this velocity code: in the page: http://localhost:8080/xwiki/bin/edit/Paréééént/sousParent/WebHome $doc.documentReference.hasParent('space:Paréééént') doesn't work (false) $doc.documentReference.hasParent('space:xwiki:Paréééént') work well (true)
$doc.documentReference.hasParent('space:sousParent') doesn't work (false) $doc.documentReference.hasParent('space:xwiki:Paréééént.sousParent') work well (true)
Indeed I skipped the fact that hasParent does not resolve the parameter, it has to be the full reference so indeed you have to explicitly indicate the wiki or it won't match the document wiki. Then it depend what is your exact use case: * if you want to check if the document in in the space "Paréééént" of the current wiki then you should resolve "Paréééént" and then passe the resolved reference to hasParent * if you know you are searching in wiki "xwiki" then it's fine with hasParent('space:xwiki:Paréééént')
_______________________________________________ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne