Get tagged documents in main wiki from subwiki?

I’m trying to work out if I can include a page from a single page and its children on the main wiki automatically using tags from the current page in a subwiki.

The Main Wiki contains page under xwiki:DeviceInformation and has children pages for the Manufacturer then model so that info only needs to be entered once per device here. The page for each device will be tagged with whatever the model number is “phone1”, 'PC2", “PrinterA” etc.

The Subwikis for Customer Data will have a page that says what device types they have onsite I.E. Customer “CompanyABC” had devices “XYZ” & “abc” onsite. If I tag the page with “PC2” and “phone1” then find the tagged pages in xwiki:DeviceInformation.WebHome and it’s children and include the data for easy veiwing.

So far I’ve only been able to get Documents from within the same wiki that have been tagged. I’ve tried using the context macro but still only get pages within the same wiki.
Is it possible to get tagged documents from another wiki? And is it possible to limit $xwiki.tag.getDocumentsWithTag(String tag) to only look at a single page and its children?

I worked out something that works for me. I know changing the database probably isn’t the best practice, but it works. The newline after the .getcontent is because I have a container macro on those pages getting included that had a error about being inline.

Now I can tag the page with a model number e.g. “PC2”. If a device page has been setup and tagged in the main wiki with “PC2” it will be included on this page.

#if ($doc.getTagList().empty)
Add Model Number Tags to add that hardware.
#set ($wikiId = $
#set ($currentWikiId = $
#set ($wikiPrefix = “${wikiId}:”)
#set ($currentTags = $doc.getTagList())
#foreach ($tag in $currentTags)
#set ($taggeddocuments = $xwiki.tag.getDocumentsWithTag($tag))
#foreach ($taggeddocument in $taggeddocuments)
#if ($xwiki.getDocument($taggeddocument).getSpace().contains(‘StringOfSpaceToLimit’))


Note that you can space-indent the velocity script (makes it easier to read).

1 Like

Thank you. I will definitely do that on future posts.

Actually I didn’t mean on the forum but in your real scripts in your wiki, to make them more readable.

In my scripts I’ve got them indented, always do. But when I copied it over something went wrong/didn’t pay enough attention.