How to show only direct childs of a space with livetable using velocity?

I want to get only direct childs (not all descendants) with the livetable of a given space.

What I have tried without success was:
‘extraParams’ : “&parent=NameOfSpaceToSearch”
‘extraParams’ : “&space=$escapetool.url(MySpaceName’)”
‘extraParams’ : “&space=${doc.space}”

My code is like this:

{{velocity}}
#set($collist = [‘doc.space’, ‘doc.creationDate’, ‘doc.date’, ‘doc.author’])
#set($colprops = {
‘doc.space’ : { ‘type’ : ‘text’, ‘link’ : ‘space’, “size” : 120 },
‘doc.creationDate’ : { ‘type’ : ‘date’ },
‘doc.date’ : { ‘type’ : ‘date’ },
‘doc.author’ : { ‘type’ : ‘text’, ‘link’ : ‘author’ }
})
#set($options = {
‘translationPrefix’ : ‘xe.index.’,
‘rowCount’ : 50,
‘extraParams’ : “&location=$escapetool.url(‘NameOfSpaceToSearch.StartingStringOfChild’)”,
‘description’ : ‘This table lists all the documents found on this wiki. The columns can be sorted and some can be filtered.’
})
#if(!$isGuest)
#set($discard = $collist.add(’_actions’))
#set($discard = $colprops.put(’_actions’, { ‘actions’ : [‘rights’] }))
#end
#livetable(‘alldocs’ $collist $colprops $options)
{{/velocity}}

It would be nice if someone could help me.

The ‘extraParams’ live table parameter is documented here http://extensions.xwiki.org/xwiki/bin/view/Extension/Livetable+Macro#HParameter24options , and I can see:

space: Find all the documents from a given specific space (Nested Spaces are not included). Example: “extraParams”: “&space=${doc.space}” (for all the documents in the current space).

Isn’t this what you want?

Hope this helps,
Marius

Sorry I did not mentioned it, but with “extraParams”: “&space=${doc.space}” I get only the name of current space returned, i.e. a single entry, the parent of my pages I am looking for.
Perhaps I am doing something else wrong (the applied script is attached).

I have tried “extraParams”: “&space=$escapetool.url(MySpaceName’)” before with the same result. I get only the name of space returned not the direct childs.
(I will add it to the unsuccessful tries section in my first post.)

So the question is open again!
Are there any other suggestions, to get just the direct children of a space?

I think you need to read about the distinction between terminal and non-terminal (nested) pages. http://www.xwiki.org/xwiki/bin/view/Documentation/UserGuide/Features/ContentOrganization/#HTerminology . You probably have something like this:

A.WebHome
A.B.WebHome
A.C.WebHome

When you tell the live table return the pages with space=A it will return only “A.WebHome”, because at the low level that’s the only direct child. A.B.WebHome has space=A.B and A.C.WebHome has space A.C.

So what you want is:

  • direct terminal child pages (you get them easily with space=A)
  • direct nested child pages (A.?.WebHome); this part is complex; there’s no predefined parameter for this AFAIK, so you’d have to create a custom live table results page (reusing Velocity macros from XWiki.LiveTableResultsMacros).

Hope this helps,
Marius

OK, So let me redefine my problem:
What I want is the child space name of a space.
From

A.WebHome
A.B.WebHome
A.C.WebHome

that would be just B and C from (not A.B, not A.B.WebHome).

Is there a way to apply an addtional filter before the entries are output with livetable?

So with ‘extraParams’ : “&location=$escapetool.url(‘A.’)”, I get everything.
I have to cut an entry string from the first . (dot) to the next . (dot) to get the B or C.
Perhaps with the option queryFilters.

Are there are other possibilies beside livetable to achieve this?

Perhaps the following velocity script could be extended to filter what I want and perhaps put in into a sortable table:

{{velocity}}
This is the list of all the spaces of the wiki
#set($spaceList = $xwiki.getSpaces())
#foreach($space in $spaceList)
  * $space
#end
{{/velocity}}

This reports the same entries as livetable with ‘extraParams’ : “&space=$escapetool.url(MyTopSpaceName’)”.

I build some ugly velocity script which outputs at least the direct child spaces of a top space MyTopSpace.
Its ugly because a . (dot) ‘inside’ a space name is not allowed.

{{velocity}}
This is a list of all the direct child spaces of a specified top space:
#set($topSpace = 'MyTopSpace.')
#set($spaceList = $xwiki.getSpaces())
#foreach($space in $spaceList)
  #if ($space.contains($topSpace))
   #set($SpaceWithoutDots = $space.replace(".", ""))
   ## test if there is only one . (dot) inside
   #if ($space.length() - $SpaceWithoutDots.length()==1)
     $space.replaceFirst($topSpace, "")
   #end
  #end
#end
{{/velocity}}

But now how to make links out of it and put in inside a sortable table?

Sure, it’s quite simple actually. Look for “List child spaces” on http://extensions.xwiki.org/xwiki/bin/view/Extension/Query+Module .

select space.name from XWikiSpace as space where space.parent = ‘Parent Space’

Unfortunately there’s no easy way to do this with the live table ATM, but as I said, you can write a custom live table results page.

Yes,
$query = "select space.name from XWikiSpace as space where space.parent = 'ParentSpaceName' order by space.name asc")
seems to be a better solution.

But now I have the problem inserting the results into a table.
In the editor it looks ok (each item in its single row), but in the preview or the normal page everything is put into a single row with a single link to the local page.

What I am doing wrong?

Here the code:

{{velocity}}
  $xwiki.jsfx.use("js/xwiki/table/tablefilterNsort.js")
  $xwiki.ssfx.use("js/xwiki/table/table.css")
{{/velocity}}

(% id="clientList" class="doOddEven filterable grid sortable" %)
(% class="sortHeader" %)|=
Header 1
   {{velocity}}
#set($query = "select space.name from XWikiSpace as space where space.parent = 'ParentSpaceName' order by space.name asc")
#foreach($item in $services.query.xwql($query).execute())
(% style="text-align: left;" %)| $item
#end
   {{/velocity}}

Hello,

It seem that you had an annoying end of line (after header)

{{velocity wiki=true}}
#set ($discard=$xwiki.jsfx.use("js/xwiki/table/tablefilterNsort.js"))
#set ($discard=$xwiki.ssfx.use("js/xwiki/table/table.css"))


(% id="clientList" class="doOddEven filterable grid sortable" %)
(% class="sortHeader" %)|=Header 1
#set($query = "select space.name from XWikiSpace as space where space.parent = 'ParentSpaceName' order by space.name asc")
#foreach($item in $services.query.xwql($query).execute())
(% style="text-align: left;" %)| $item
#end
{{/velocity}}

Note you can enclose your style with:
http://www.xwiki.org/xwiki/bin/view/Documentation/UserGuide/Features/XWikiSyntax/?syntax=2.1&section=Paragraphs
and
http://www.xwiki.org/xwiki/bin/view/Documentation/UserGuide/Features/XWikiSyntax/?syntax=2.1&section=Groups

Pascal B

1 Like

I’m facing a similar problem and don’t get it. I have:

Referenzberichte.WebHome
Referenzberichte.B (Terminal Page)
Referenzberichte.C (Terminal Page)

In Referenzberichte.WebHome i want to disable a livetable which shows B and C, but NOT Referenzberichte.WebHome, I use:

{{velocity}}
#set($collist = ['doc.name', 'doc.space', 'doc.date', 'doc.author'])
#set($colprops = {
  'doc.name' : { 'type' : 'text' , 'size' : 30, 'link' : 'view' },
  'doc.space' : { 'type' : 'text', 'link' : 'space' },
  'doc.date' : { 'type' : 'date' },
  'doc.author' : { 'type' : 'text', 'link' : 'author' }
})
#set($options = { 
  'translationPrefix' : 'xe.index.',
  'description' : 'This table lists all the documents found on this wiki. The columns can be sorted and some can be filtered.',
  "tagCloud" : true,
  "extraParams" : "&space=Referenzberichte&location!=WebHome"
})
#livetable('rb' $collist $colprops $options)
{{/velocity}}

Why does it list Referenzberichte.WebHome? How do I do a “not equal” operator for location?

Yes, Pbas it is working now.

Nice, thank you for your hints.

Here for the sake of completeness the full code with clickable links inside the table, which is a replacement of a livetable for me (my demands).
You can seach for direct child spaces and sort the list.

#set($MyTopSpaceName='AddParentSpaceNameHere')
#set($MyTopSpace="'${MyTopSpaceName}'")
**list all direct space names of the specified space:**
(% id="clientList" class="doOddEven filterable grid sortable" %)
(% class="sortHeader" %)|=Header 1
#set($query = "select space.name from XWikiSpace as space where space.parent = $MyTopSpace order by space.name asc")
#foreach($item in $services.query.xwql($query).execute())
(% style="text-align: left;" %)|[[$item>>doc:${MyTopSpaceName}.${item}.WebHome]]
#end{{/velocity}}

Hello, what you can do is … hidden Referenzberichte.WebHome page.maybe.
Referenzberichte.WebHome could be find in breadcrumb still