cogCreates a page containing the titles and text content of all sibling pages, to allow export to RTF or PDF. Ensures pages are ordered by title alphabetically (unlike the standard export). Snippet is in Python.
Developed by

Tim Meneely

0 Votes
LicenseGNU Lesser General Public License 2.1


Warning: I'm new to XWiki, and in particular to scripting it - but I found a way to do what I want that seems to do what you want, using a script (I used Python because I know Python).

My situation:

  • I'm writing a novel in xWiki.
  • Using xWiki 11.6. I didn't research backward compatibility.
  • I have a single "parent" page that's not very meaningful (and it gets ignored in my script), and all the information I want to print is in child pages off of that.
  • The titles of the child pages are what I want to sort on; I start them with sequence numbers to make this obvious, e.g, "0001 First page," "0002 Page that will print second," etc.
  • My child pages are only one layer deep. Layers could be accommodated with a loop; I didn't (yet).

What I want:

  • To print the whole novel, except:
  • There are some child pages I don't want to print. I created my own convention: Their titles contain the phrase, "DO NOT PRINT". (Position within the title doesn't matter).
  • I want to print the page title as an H2, then the page contents, then a breaker line.

What I did:

  • Created a new and dedicated child page (called "Entire book DO NOT PRINT").
  • Put the Python script below on that child page (clicked on "Source" and pasted this).
  • Put a link to this child page on the parent page. When I want to export the whole story, I go to this child page and just export (PDF, RTF, whatever) that single page.
sql = "where doc.parent='"+doc.parent+"' and doc.title not like '%DO NOT PRINT%' order by doc.title"
for item in xwiki.searchDocuments(sql):
 d = xwiki.getDocument(item)
 print "==",d.title,"=="
 print d.content
 print "----"

(The four lines after the "for item..." line are indented two spaces. Python...)

Other characteristics you could print (other than "d.title" and "d.content") would be I think those listed on [this link in the docs.]( Replace "XWD_" with "d." and add it to the loop.

I hope this is helpful.

Prerequisites & Installation Instructions

Copy the code snippet to a page and save it.

Created by Tim Meneely on 2019/08/09 20:19

Get Connected