Is it possible to list pages with a short annotation using a macro or script?

I would like to display a list of child pages.
so that small annotations about these pages are additionally displayed. For example, specially filled text in a field or the first 100 characters. Is there some method for doing this?

Yes this is quite easy to do with scripting. You need to start defining where you find that metadata about each page. One way is to create an XClass and add an xobject to each page containing the info you wish.

Then you can use a XWQL Query to find nested pages having such an xobject, see https://extensions.xwiki.org/xwiki/bin/view/Extension/Query%20Module

1 Like

Thanks, I’ll try to do it tomorrow

Thank you! I tried to use string field to add title for links in tree (see below). But if any one have better ideas how to use annotations for pages list i will glad to see it.

{{tree links="true"}}
{{velocity}}
{{html wiki=true}}
<ul>
#foreach ($child in $doc.getChildren())
  <li class="jstree-open">
  #set ($childDoc = $xwiki.getDocument($child))
  #set($anot = $childDoc.getObject('XWiki.ApiDescriptionClass'))
<a href="$xwiki.getURL($childDoc)" title="$anot.Annotation"> $xwiki.getDocument($child).getDisplayTitle()</a>
    <ul>
    #foreach ($subchild in $xwiki.getDocument($child).getChildren())
      <li class="jstree-open">
  #set ($childDoc = $xwiki.getDocument($subchild))
  #set($anot = $childDoc.getObject('XWiki.ApiDescriptionClass'))
<a href="$xwiki.getURL($childDoc)" title="$anot.Annotation"> $xwiki.getDocument($child).getDisplayTitle()</a>
        <ul>
        #foreach ($subsubchild in $xwiki.getDocument($subchild).getChildren())
          <li class="jstree-open">
            [[$subsubchild]]
            <ul>
            #foreach ($subsubsubchild in $xwiki.getDocument($subsubchild).getChildren())
              <li class="jstree-open">
                [[$subsubsubchild]]
              </li>
            #end
            </ul>
          </li>
        #end
        </ul>
      </li>
    #end
    </ul>
  </li>
#end
</ul>
{{/html}}
{{/velocity}}
{{/tree}}

So you got the metadata right but the iteration on children is not very scalable and also doesn’t show nested levels properly.

I think a more scalable solution would be to customize the Document Tree macro, see https://extensions.xwiki.org/xwiki/bin/view/Extension/Document+Tree+Macro#HCustomDocumentTree

1 Like

Thanks a lot for your help. I’ll try to take this code later.
But in fact, I chose the document tree, because I couldn’t implement anything better.

I wanted something like a page link + short annotation with accordion (slider) but couldn’t do it

When I try to put a custom tree, I see this:
image

Could you please give me an example of how to add title to links in custom three? I could not get

Hello, I’m missing good examples. If you can please tell me how to add the title attribute to a_attr: {} for objects in the custom tree: {} (I looked at https://www.jstree.com/docs/json/)

I got code from https://extensions.xwiki.org/xwiki/bin/view/Extension/Document%20Tree%20Macro#HExcludenodesbasedontheirids and added my class data to links title.

{{include reference="XWiki.DocumentTreeMacros"/}}

{{velocity output="false"}}
#macro (filterChildren $children)
  
  #set ($filteredChildren = [])
  #foreach ($child in $children)
     
      #set($childDoc = $xwiki.getDocument($child.data.id))
      #set ($anot = $childDoc.getObject('XWiki.ApiDescriptionClass'))
      #set ($child.a_attr.title=$anot.Annotation)
      #set ($discard = $filteredChildren.add($child))
        
      
  #end
  #set ($discard = $children.clear())
  #set ($discard = $children.addAll($filteredChildren))
#end
{{/velocity}}

{{velocity wiki="false"}}
#if ($xcontext.action == 'get')
  #updateDocTreeConfigFromRequest
  #if ($request.data == 'children')
    #set ($children = $NULL)
    #getChildren($request.id $children)
    #if ($children)
      #filterChildren($children)
      #set ($discard = $response.setContentType('application/json'))
      $jsontool.serialize($children)
    #else
      $response.sendError(404);
    #end
  #else
    ## Continue with the default behaviour.
    #handleDocumentTreeRequest
  #end
#end
{{/velocity}}

I’ve added https://extensions.xwiki.org/xwiki/bin/view/Extension/Document%20Tree%20Macro#HDebugging to help you out. Let me know if it helps.

1 Like

i understood it yesterday, when write my script. But it will be very helpful for other people. Thank you!

I have new problem. When i use this example script https://extensions.xwiki.org/xwiki/bin/view/Extension/Document%20Tree%20Macro#HExcludenodesbasedontheirids links in tree not work. In html links still tags and they have correct href, but they not work when click

UPD: I found parameter links=“true” and it’s solve my problem