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 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 vote
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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Asked May 24, 2018 in Confluence

What are the resources that you use to learn more about Atlassian Products?

I am gathering information about resources available for Atlassian product knowledge transferring for a presentation in our local Atlassian User Group. I want to group them in four categories From ...

603 views 18 16
View question

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