Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to create links to pages that will be displayed on linked page?

Martin Heinemann
Contributor
October 20, 2014

Hi,

is there a way or a macro, which allows to create a link to a target-page and creates automatically a back link to the source-page on the target page?

 

Source-Page:                  Target-Page:

Link(target-page) -------->

                  <---------------- Link (source-page)

 

I need this to create a very simple kind of database. Each database entry has a confluence page with page-properties and sometimes a page can have a link (like a database relation) to another page.

I can do this by hand but this is a lot of work.

 

thanks

 

 martin

 

2 answers

1 accepted

1 vote
Answer accepted
Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 21, 2014

Here is a user macro that will make a list of the referring links to a page. You can tweak it to fit your needs.

## Developed by: Davin Studer
## Date created: 06/26/2014
## @noparams
#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($linkManager=$containerContext.getComponent('linkManager'))

#set($pages = $linkManager.getReferringContent($content))

#if($pages.size() &gt; 0)
&lt;ul class="referring-content-links"&gt;
#foreach($page in $pages)
    &lt;li&gt;&lt;a href="$page.getUrlPath()"&gt;$page.getTitle()&lt;/a&gt;&lt;/li&gt;
#end
&lt;/ul&gt;
#end

 

You can put this into your Page Layout decorator (Confluence Admin -> Look and Feel -> Layouts) if you want it to show on every page.

$helper.renderConfluenceMacro("{referring_content}")
Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 23, 2014

Is this what you are looking for?

Martin Heinemann
Contributor
October 23, 2014

Well, it is a first step. As i am a developer but do not have any knowledge of the macro language, it seems hard to get to the result. As the reciprocal linkin would be inside the key-value table of page properties, the macro should check wether the link on the refering page is also placed inside a key-value table, or better, is the value of a specific key in the table. Is there a way to do this with the macro language?

Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 24, 2014

It's might be possible ... you'd have to parse the page xml to do it though. Check the below links for information regarding the Velocity Templating Language and the Confluence API. https://confluence.atlassian.com/display/DOC/User+Macro+Template+Syntax https://developer.atlassian.com/display/CONFDEV/Confluence+Objects+Accessible+From+Velocity

Martin Heinemann
Contributor
October 27, 2014

Is this all possible by a user macro or do i need to create a normal macro?

Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 27, 2014

Without trying to develop it my self I can't be certain if it could all be done in a user macro. Honestly, it probably would not be very performant in a user macro as you would first have to get this list of pages link to a page then for each link you would have to get the page xml and parse it. If you had lots of links that could get VERY slow.

Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 27, 2014

If you want something that does everything you want you will probably have to brush up on your Java and Velocity and roll your own.

0 votes
Alejandro Conde Carrillo
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 21, 2014

Hello Martin.

There is not a way to add a reciprocal link in the page content. You could check the Page information  (Tools > Page Information) where a list with the incoming list is displayed.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events