I would like to be able to get document content from other pages, line by line, section by section. I am currently able to get the full document using the following code:
#set ($xwql = "where doc.space like 'my space%'")
#foreach ($item in $services.query.xwql($xwql).execute())
===**[[$item]]**===
#set($document = $xwiki.getDocument($item))
$document.getContent()
#end
By including/excluding specific sections, I’m looking to replicate the behavior of the “include page” macro which has a feature of only retrieving specific sections.
I am unsure of what to do at “render lines here”. I need some kind of XDOM getter function that takes as a parameter a header, but I have yet to find one.
You need to find the SectionBlock instead of the HeaderBlock (the Header Block only contains the heading, as children). The children of the SectionBlock contains the content of the section.
The only issue now is I’d like to be able to read in each line of the section one at at a time. My previous method where I use getBlocks with class:ParagraphBlock won’t work though. I tried playing with the code and this is what I came up with:
#set( $xwql = "select doc from Document as doc where doc.parent like '%006 test.WebHome' order by doc.title")
#set ($items = $services.query.xwql($xwql).execute())
#foreach ($item in $items)
#set($document = $xwiki.getDocument($item))
===**[[$item]]**===
#foreach ($block in $document.getXDOM().getBlocks('class:SectionBlock', 'DESCENDANT'))
#set ($xwikiSyntax = $services.rendering.render($block, "xwiki/2.1"))
#set ($t = $block.getChildren())
$t
#end
#end
This will then output an array of all the headers and paragraph blocks i.e.
However, when I try to call $services.rendering.render on $t, I get no output. If I could get the actual content from these elements, I would have what I need. If anyone knows how to do that, please let me know.
The render() API takes a Block as the first parameter but you’re passing it a List, so it cannot work. You should wrap the List in a CompositeBlock. However there’s no script API to do this from Velocity