I want to check if page with specific name is exist in current space.
And do something if result in positive.
Use case: template with Excerpt Include macro (with predefined page to display) which have to render only if predefined page exits.
Currently if predefined page isn't exist then Excerpt Include macro throws huge log in atlassian-confluence.log
Just created an own user macro:
## Macro title: Verify Page ## Macro has a body: Y ## ## Developed by: Marcel Woschek ## Date created: 18/08/2016 ## Installed by: Marcel Woschek ## ## @param Pagename:title=pagename|type=string|required=true ## ## Get PageManager object instance #set($containerManagerClass=$content.class.forName('com.atlassian.spring.container.ContainerManager')) #set($getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null)) #set($containerManager=$getInstanceMethod.invoke(null,null)) #set($containerContext=$containerManager.containerContext) #set($pageManager=$containerContext.getComponent('pageManager')) ## Get the Page object instance #set($page=$pageManager.getPage($space.key,$paramPagename)) #if($page) $body #end
You just need to put the Excerpt Include macro into the body of this macro
Really appreciate your help. It helped to avoid unnecessary log.
I added default value (page name to check) to parameter and Excerpt Include macro with page name to display in case this page exist.
## @param Pagename:title=pagename|type=string|required=true|default=Schedule ## Get PageManager object instance #set($containerManagerClass=$content.class.forName('com.atlassian.spring.container.ContainerManager')) #set($getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null)) #set($containerManager=$getInstanceMethod.invoke(null,null)) #set($containerContext=$containerManager.containerContext) #set($pageManager=$containerContext.getComponent('pageManager')) ## Get the Page object instance #set ($spacekey=$space.key) #set($page=$pageManager.getPage($spacekey,$paramPagename)) #if($page) <ac:macro ac:name="excerpt-include"> <ac:parameter ac:name="nopanel">true</ac:parameter> <ac:default-parameter>Schedule</ac:default-parameter> </ac:macro> #end
Could you explain "Get PageManager object instance" code? Is it the way to get access to page name?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need the PageManager to verify if the page exists in the given space.
$pageManager
.getPage(
$spacekey
,
$paramPagename
) tries to get the $page object using the spacekey and the pagename, because the combination of spacekey and pagename is unique. If the page doesn't exist, this method returns null.
The #if statement then checks if the $page object is not null, hence if the page exists.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you only want to use it for the Excerpt Include Macro you can also integrate it in that selfmade macro:
## Macro title: Excerpt Include if Page Exists ## Macro has a body: N ## ## Developed by: Marcel Woschek ## Date created: 18/08/2016 ## Installed by: Marcel Woschek ## ## @param Pagename:title=pagename|type=string|required=true ## ## Get PageManager object instance #set($containerManagerClass=$content.class.forName('com.atlassian.spring.container.ContainerManager')) #set($getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null)) #set($containerManager=$getInstanceMethod.invoke(null,null)) #set($containerContext=$containerManager.containerContext) #set($pageManager=$containerContext.getComponent('pageManager')) ## Get the Page object instance #set($page=$pageManager.getPage($space.key,$paramPagename)) #if($page) <ac:macro ac:name="excerpt-include"> <ac:parameter ac:name="nopanel">true</ac:parameter> <ac:default-parameter>$paramPagename</ac:default-parameter> </ac:macro> #end
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.