Extract page link from include page macro

Is there a way to extract the url/xwiki address of the include page macro from velocity?

For example, if you have Page AA and include it in Page A and then include Page A in Page B, how do I extract the Page address from Page A (resulting in the direct content of Page AA) so that I can access it from Page B?

Phrasing the question in a different way, when I look at the source of a page that includes another page, it will have the following directive:

{{include reference=“my wiki adrress’.WebHome”/}}

What I’m looking for is a way to parse a page from velocity such that I can get the address referenced at “includ reference”.

Thank you.

Hi,

Yes it’s possible using the XDOM API. See https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Scripting/APIGuide/#HFindXDOMBlocks

Example:

{{include reference="xxx"/}}

{{velocity}}
#set($blocks = $doc.getXDOM().getBlocks('class:MacroBlock', 'DESCENDANT'))
#foreach ($block in $blocks)
  #if ($block.id == 'include')
    * Include reference = $block.getParameter('reference')
  #end
#end
{{/velocity}}