Confluence出口问题

时间:2013-09-04 14:43:59

标签: pdf macros export confluence

我们创建了一个自定义用户宏,用于创建子页面表,此表还填充了上次更新,版本,更新等信息。

导出页面时会填充表格,但是当您导出空格时,表格为空。

代码在

之下
## Macro title: Page Data
## Macro has a body: N
## Body processing: n/a
## Output: HTML
##
## Developed by: Brian Mitchell
## Date created: 06/27/2013
## @noparams

#set ($PageTitle = $content.displayTitle)
#set ($PageVersion = $content.version)
#set ($PageDate = $action.dateFormatter.formatGivenString("dd MMM yyyy",    $content.lastModificationDate))
#set ($PageAuthor = $content.lastModifierName)
#set ($pageListArray = [])
#set ($currentPage = $action.page)
#set ($spaceHome = $space.getHomePage())

#macro ( process $rp )
 #set ($pagelist = $rp.getSortedChildren() )  ## returns List<Page>
   #foreach( $child in $pagelist )
     #set($p = $pageListArray.add( $child ) )
       #if( $child.hasChildren() )
          #process ( $child )
    #end
 #end
#end

    #process ($currentPage)


    <h1> Confluence Page Versions </h1>
    <table class="confluenceTable">
    <tbody>
   <tr>
    <th class="confluenceTh">Page Title</th>
    <th class="confluenceTh">Page Version</th>
     <th class="confluenceTh">Date</th>
     <th class="confluenceTh">Changed By</th>
    </tr>

    <tr>
    <td>$PageTitle</td>
     <td><a href=http://confluence.mango.local/pages/viewpreviousversions.action?pageId=$content.getIdAsString()>$PageVersion</a></td>
      <td>$PageDate</td>
     <td>$PageAuthor</td>
     </tr>


      #foreach( $child in $pageListArray)   ## child is of type Page
        <tr>
      <td class="confluenceTd">$child.getTitle()</td>
        <td class="confluenceTd"><a href=http://confluence.mango.local/pages/viewpreviousversions.action?pageId=$child.getIdAsString()>$child.getVersion()</a> </td>
        <td class="confluenceTd">$action.dateFormatter.formatGivenString("dd MMM yyyy", $child.getLastModificationDate())</td>
          <td class="confluenceTd">$child.getLastModifierName()</td>
  </tr>
            #end

         </tbody>
        </table>

如何编辑代码以将空间的全部内容放入数组中,然后在导出时填充表

所以我替换了           #process($ currentPage)

          #process($ spaceHome)

所以我认为问题出在太空出口上,以下命令不起作用 #set($ currentPage = $ action.page)

有没有人对我可以使用的内容有任何想法?

1 个答案:

答案 0 :(得分:0)

$action Velocity变量指的是当前正在执行的操作。在进行空间导出的情况下,$action引用“导出空间”操作而不是“导出页面”操作,并且由于“导出空间”操作没有可从操作对象获得的page变量,您的$action.page不会返回任何内容。

但是,您很幸运:导出空间功能确实传递了当前正在导出的页面的上下文,您已经在使用它了! $content指的是正在导出的ContentEntityObject,这实际上与您尝试从$action.page获取的内容相同。

要修复您的示例,只需调整对#process宏的调用即可使用$content。在Confluence 5.5上导出整个空间时,以下内容适用于我:

## Macro title: Page Data
## Macro has a body: N
## Body processing: n/a
## Output: HTML
##
## Developed by: Brian Mitchell
## Date created: 06/27/2013
## @noparams

#set ($PageTitle = $content.displayTitle)
#set ($PageVersion = $content.version)
#set ($PageDate = $action.dateFormatter.formatGivenString("dd MMM yyyy",    $content.lastModificationDate))
#set ($PageAuthor = $content.lastModifierName)
#set ($pageListArray = [])
## #set ($currentPage = $action.page)
#set ($spaceHome = $space.getHomePage())

#macro ( process $rp )
 #set ($pagelist = $rp.getSortedChildren() )  ## returns List<Page>
   #foreach( $child in $pagelist )
     #set($p = $pageListArray.add( $child ) )
       #if( $child.hasChildren() )
          #process ( $child )
    #end
 #end
#end

    #process ($content)


    <h1> Confluence Page Versions </h1>
    <table class="confluenceTable">
    <tbody>
   <tr>
    <th class="confluenceTh">Page Title</th>
    <th class="confluenceTh">Page Version</th>
     <th class="confluenceTh">Date</th>
     <th class="confluenceTh">Changed By</th>
    </tr>

    <tr>
    <td>$PageTitle</td>
     <td><a href=http://confluence.mango.local/pages/viewpreviousversions.action?pageId=$content.getIdAsString()>$PageVersion</a></td>
      <td>$PageDate</td>
     <td>$PageAuthor</td>
     </tr>


      #foreach( $child in $pageListArray)   ## child is of type Page
        <tr>
      <td class="confluenceTd">$child.getTitle()</td>
        <td class="confluenceTd"><a href=http://confluence.mango.local/pages/viewpreviousversions.action?pageId=$child.getIdAsString()>$child.getVersion()</a> </td>
        <td class="confluenceTd">$action.dateFormatter.formatGivenString("dd MMM yyyy", $child.getLastModificationDate())</td>
          <td class="confluenceTd">$child.getLastModifierName()</td>
  </tr>
            #end

         </tbody>
        </table>