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)

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<p>v10</p> instead of

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


1 answer

0 votes
David Simpson Community Champion Nov 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.

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
Community showcase
Published Dec 18, 2018 in Confluence Cloud

Happy holidays from our team to yours!

Hi Community!  2018 was filled with changes for our team, both big and small, and we've taken a lot of time to both celebrate our wins and recognize areas of improvement. One thing that we're a...

484 views 3 18
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