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?
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:
<a href="${req.contextPath}/pages/createpage.action?spaceKey=spaceKeyOfPage&title=${generalUtil.urlEncode($row.program)}&linkCreation=true">$row.program</a>
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 <a href="${req.contextPath}${myLinkedPage.getUrlPath()}">$row.program</a> #else ## page doesn't exist yet <a href="${req.contextPath}/pages/createpage.action?spaceKey=spaceKeyOfPage&title=${generalUtil.urlEncode($row.program)}&linkCreation=true">Create page: $row.program</a> #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)
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Duncan! I voted on all your questions ;). You should be able to obtain the spaceKey with $page.spaceKey
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you, I've been battling this one for nearly an hour thinking it was a velocity issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
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.