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. I suppose I must use all space path.
Another point about documentation http://extensions.xwiki.org/xwiki/bin/view/Extension/Model+Module#HScriptSer... (because I spend a lot of time to identify my issue because the "x" characters:
Create a Document Reference: "#set ($reference = $services.model.createDocumentReference("wiki", ["space"], "page"))"
but
$doc.documentReference.spaceReferences.get(0) display "Space xwiki:Encyclopédie".
Reference use "xwiki" but createDocumentReference use "wiki"?
"wiki" is it a wiki name example?
I don't really understand your example $services.model.createDocumentReference("wiki", ["space"], "page") have nothing to do with $doc.documentReference. It just means you are executing this script on main wiki ("xwiki").
Another question: What is the difference between:
$services.model.createDocumentReference and services.model.resolveDocument?
With resolveDocument the Page must exist?
Can I use CreateDocumentReference if target document exist?
resolveDocument take a reference as a String and parse it (it's using a DocumentResolver component for this) and find what is not provided in the String (by default from the context) while createDocumentReference takes each element of the reference separately and know nothing about reference syntax.
I mean: is it the same utility? #set ($reference = $services.model.createDocumentReference("wiki", ["space1","space2"], "page")) #set ($reference = $services.model.resolveDocument("wiki:space1.space2.page))
Last point: I think these 2 simples examples missing
in: http://extensions.xwiki.org/xwiki/bin/view/Extension/Model+Module#HScriptSer...
#set ($reference = $services.model.resolveSpace('xwiki:MySpace')) #set ($reference = $services.model.resolveSpace('xwiki:MySpace.MyPage')) What do you think?
Not sure people create space references that much but sure why not.
Sorry I wanted to write: #set ($reference = $services.model.resolveSpace('xwiki:MySpace')) #set ($reference = $services.model.resolveDocument('xwiki:MySpace.MyPage')) but mayb it is not necessary because you told me than xwiki automatically convert parameters to the right type.