Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Add links to (possibly) new pages in PocketQuery template

Duncan Kinnear November 24, 2015

I've got a PocketQuery template which lists program names and descriptions as found in a database table.

I want the program name to be a link to a documentation page about that program, but the page may or may not exist.

I've tried the following so far:

$PocketQuery.renderWikiMarkup('[$row.program]')
$PocketQuery.renderXhtml('<ac:link>$row.program</ac:link>')
#contentLink2($row.program false false)

But none of these work.

Is there another way to do this? Is there documentation somewhere that gives this kind of information/examples?

3 answers

1 accepted

2 votes
Answer accepted
Felix Grund (Scandio)
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.
November 26, 2015

Hi Duncan,

Since PQ templates are rendered in view mode, you can't use any editor features or XHTML content. But you can easily do it with Velocity programming.

If you simply only need the link with always the same text and no other logic, you can simply use a createpage link. If the page already exists, there will simply be a redirect to that page:

&lt;a href="${req.contextPath}/pages/createpage.action?spaceKey=spaceKeyOfPage&amp;title=${generalUtil.urlEncode($row.program)}&amp;linkCreation=true"&gt;$row.program&lt;/a&gt;

If you need some more logic, you can also do this and check if the page exists first:

#set($myLinkedPage = $pageManager.getPage("spaceKeyOfPage", $row.program))
#if ($myLinkedPage) ## page already exists
	&lt;a href="${req.contextPath}${myLinkedPage.getUrlPath()}"&gt;$row.program&lt;/a&gt;
#else ## page doesn't exist yet
	&lt;a href="${req.contextPath}/pages/createpage.action?spaceKey=spaceKeyOfPage&amp;title=${generalUtil.urlEncode($row.program)}&amp;linkCreation=true"&gt;Create page: $row.program&lt;/a&gt;
#end

Simply replace the spaceKeyOfPage in both cases with the key of the space where the page should be.

Does this help?

Regards, Felix (Scandio)

Duncan Kinnear November 29, 2015

Thanks Felix, the first option you gave me works really well. You don't notice it redirecting to pages that already exist. By the way, I haven't answered your other comment on the Nested Queries question as I don't have enough rep on here to do more than 1 thing in 24 hours. Any help with that would be appreciated (voting on my questions?). Also, is there a way to get the space key in the velocity code? I tried using #set($spacekey = $content.getSpaceKey()) which I saw on another answer, but it doesn't seem to work.

Felix Grund (Scandio)
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.
November 29, 2015

Hi Duncan! I voted on all your questions ;). You should be able to obtain the spaceKey with $page.spaceKey

Duncan Kinnear November 30, 2015

Thanks Felix, $page.spaceKey works! :-)

Nathaniel Wright May 11, 2016

Thank you, I've been battling this one for nearly an hour thinking it was a velocity issue. 

0 votes
Duncan Kinnear November 26, 2015

It is just the name of a program, like 'abcxyz'. I want to use that to have a link to a page in this space called 'abcxyz' that describes what that program does. But obviously we don't have pages yet for the 3,500 programs in our system, so the links need to point to pages that don't exist yet. Essentially I need the same functionality as if I have typed [abcxyz] in the editor. Confluence knows it's a link, but the page doesn't exist yet, and Confluence gives you a (different coloured) link to create that page. Does that make sense?

0 votes
Felix Grund (Scandio)
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.
November 25, 2015

Hi Duncan! Thank you for your interest in PocketQuery! What exactly is $row.program? Is it an URL to a Confluence page? Do I understand you right that you want to display the link only if it is a valid page link?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events