how to get a page content body via velocity in a user macro?

Using CONF 5.5.7 I want to get the content (body) of one specific page to show it on another page.
I dont want to use the include macro for permissions reasons. In a restricted space there is just one page that has to be shown in another public space. Secure-include macro doesn't work here. Maybe an issue with HTTPS.
The following user macro works fine to show the homepage of a specific space in another space's page:

#set($space = $spaceManager.getSpace("myKey") )
#set($homepage = $space.getHomePage() )
$homepage.getBodyAsString()

But how can I get the body of another specific page of that space? I can't find a method getPage(pageid) to use in my user macro.
Any idea?
Many thanks.

 

2 answers

1 accepted

This widget could not be displayed.
Stephen Deutsch Community Champion May 12, 2015

Hi Stefan,

This is what I did (note that it is not secure to let the user choose the page ID):

## @param PageToInclude:title=Page ID of page to include|type=string|required=true
#set ( $Long = $generalUtil.getSystemStartupTime() )
#set ( $pageId = $Long.parseLong($paramPageToInclude) )
#set ( $page = $pageManager.getPage($pageId) )
#set ( $pageContent = "Page not Found" )
#set ( $pageContent = $page.getBodyAsString() )
$pageContent
This widget could not be displayed.

My first thought is to put the original content in the public space, then use the include-page macro to have the content shown in the restricted space.

I dropped a couple of variations of the include macro into bitbucket a while back.  One is include-with-replacement, the other is a shared-block with and without replacement.  The shared block is much like the excerpt macro with the exception that you can have multiple blocks per page.  If for security reasons you want to have the macro limit access to just one page or some sort of rules, you could hard code that logic into the macros.

https://bitbucket.org/selberg/include-content

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published yesterday in Marketplace Apps

The 7 hacks of highly successful automation

...there's anything I've learnt from working, it's that people are lazy! No offense to anyone reading this, but it's true and we can all admit it. The easier you make something for someone, the more...

148 views 0 10
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you