How can I set the contents of a page include as a variable in a macro? Or can I strip out the tags from a page include?(Confluence)

Steve Goldberg
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 21, 2011

So I'm trying to do something along the lines of:

#set($paramversion = {include:globalpages:_TemplateVersionCurrent})

I want the contents of the page "_TemplateCurrentVersion" to be set as a variable so that I can use it throughout the macro.

I have tried merely using {include:globalpages:_TemplateVersionCurrent} in the places that I want it, which works to an extent, except that it also includes the <p> tags, which is no good if I am using it for a URL (as it returns "<p>v10</p>" rather than "v10"). This gets me http://mydomain.com/latesttemplates/<p>v10</p> instead of http://mydomain.com/latesttemplates/v10.

So I want to know if it's possible to strip the <p> tags out and store it is a variable.

Thanks

1 answer

0 votes
David at David Simpson Apps
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
November 21, 2011

If you want to remove the HTML tags, you could try something like this:

#set( $html = "&lt;p&gt;xxx&lt;/p&gt;" )
#set( $plain = $html.replaceAll("\\&lt;.*?&gt;","") )
$plain ## should give just "xxx"

...or similar.

This is clearly not foolproof but might be almost good enough.

Steve Goldberg
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 21, 2011

Hey David,

You are on to something. Technically what you've written is correct but it seems that when it comes to stripping out the code, it does not recognise the <p> tags when it's doing the .replaceAll function and so doesn't strip it out. This means that when it comes to putting in the URL, it still has the <p> tags in. I think it's because it doesn't see it as plain text until it reaches the URL.

Does that make sense?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events