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

This widget could not be displayed.
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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Tuesday in Confluence

Add-on evaluation with confluence templates

Atlassian market place contains number of Apps/Addons which improves the capability of out of the box Atlassian products. It is good to follow a plugin evaluation process before install add-ons. So t...

137 views 12 6
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