Good day
It looks like the TreeMacro does not like special characters in the page name. I wrote a little velocity that expands the tree using
{{tree links="true" icons="false"}}
{{velocity}}
#foreach ( $child_1 in $sorttool.sort( $doc.getChildren() ) )
<li class="jstree-open">
[[$child_1]]
<ul>
<ul>
As soon as the page has something like a tilde “~” at the start of the page name, the page itself and all nested page can no longer be access via those links generated via the TreeMacro.
The page name in this sample is:
“~ Complete”
(tilde space Complete)
This is the link generated, which does not work:
xwiki/bin/create/NetSuccess%20Internal/Organisational/Projects/Customer/%20Complete/WebHome?parent=NetSuccess+Internal.Organisational.Projects.WebHome
Clearly the tilde is not escaped in this case …
… where as the default navigation tree generates this url:
/cr/ns/xwiki/bin/view/NetSuccess%20Internal/Organisational/Projects/Customer/%7E%20Complete/
where the tilde is represented with %7E.
Is this expected or is there better way to get the correct URL then “[[$child_1]]” or do I need an additional function to make it work or might this be a bug?
Thank you
This is not a tree macro issue. You’ll get the same result if you use [[$child_1]]
outside of the tree macro and the value of $child_1
contains special XWiki Syntax characters like ~
. Generally speaking you need to escape these special characters. You can use:
[[$services.rendering.escape($child_1, $doc.syntax)]]
But, in this particular case my strong advice is to avoid mixing wiki syntax with HTML (i.e. avoid {{html wiki=true}}
). Since you already generate HTML like <li class="jstree-open">
you should also use HTML for the links. And of course, you should escape the XML (HTML) special characters when needed.
Hope this helps,
Marius
Marius
Thank you very much for the advice… I’m still learning on how to do things … I used some snippets and code I found on the internet and mixed it together / adopted / extended it. Now, here is the thing: without " html wiki=true
", this would not work
<li class="jstree-open">
[[$child_1]]
<ul>
And some parts like the space character are escaped automatically with %20, but not the tilde character …
But it works perfectly with your example, still using " html wiki=true
" … now, as I would like to learn on how to implement this properly, I tried to find out what the above does and if I understand it right, this will instruct the HTML macro to parse xWiki Syntax and echo HTML …
That said, if I would like to implement this myself without the help of the xwiki to HTML conversion, I would probably need to generate the link code, since getChildren returns a list of documents as of the API doc… I would then need to get the name and the link to the document from the list entries … and feed that to the tree macro?
I tried this:
<li class="jstree-open">
<a href="$services.rendering.escape($xwiki.getURL($child_1), $doc.syntax)">$services.rendering.escape( $xwiki.getDocument($child_1).getDocumentReference().getParent().getName(), $doc.syntax )</a>
<ul>
Which works fine as long as “html wiki=true”, if I remove that, it does not work anymore … any idea what goes on?
Well the first reason it did not work was that I removed ALL, the entire {{html wiki=“true”}} instead of only the >wiki=“true”<
This was a genius act!
Anyway, once I got that, the result was that every character had a ~ after each other. From the API I learned:
Escapes a give text using the escaping method specific to the given syntax.
One example of escaping method is using escape characters like ~
for the Syntax.XWIKI_2_1
syntax on all or just some characters of the given text.
The current implementation only escapes XWiki 1.0, 2.0 and 2.1 syntaxes.
Eg. without “html=true” this will never work out.
Now, I tried to use “$esc.html”, which does not appear to be part of Velocity in xWiki.
Well, since that was not found, tried $escapeTool to no avail … but after I posted this, I found:
where it is listed as $escapetool …
Now this is the final version of it:
#foreach ( $child_1 in $sorttool.sort( $doc.getChildren() ) )
<li class="jstree-open">
<a href="$escapetool.html( $xwiki.getURL($child_1) )">$escapetool.html( $xwiki.getDocument($child_1).getDocumentReference().getParent().getName() )</a>
<ul>
Thank you @mflorea