Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How can I avoid html encoding for Parameters in user macros

We have a user macro with a parameter of type confluence-content. When we try to get the page with a title containing special characters e.g. "This & That", the parameter returns the title encoded "This & That". So when trying to get the page from the pageManager, the page is not found. Is there a possibility to avoid the encoding of a parameter?

1 answer

0 votes
Bill Bailey Community Leader Dec 14, 2020

is your parameter type set to "type=confluence-content"? That is supposed to allow a user to run a match to existing content.

Yes, it is set to confluence-content. In a macro within a plugin, this parameter then is returned without encoding but in a user macro when rendering the velocity template, the parameter will be encoded.

Bill Bailey Community Leader Dec 16, 2020

Can you convert the results from the PageManager to encoded HTML before doing a compare? Or are you trying to do a page look up?

And how about just pulling the pageID of the desired page?

Bill Bailey Community Leader Dec 16, 2020

The other way is to parse your parameter to find replace HTML encodings. Not fun, but you can add corner cases (and tell user to please not put special characters in page names).

When using the confluence-content type for a parameter, only "spaceKey:pageTitle" is available for rendering the velocity template. I replaced the known entities now, but this is not generic and I didn't found a decoder, which is available in the rendering context and no way to avoid the encoding of the parameter.

Bill Bailey Community Leader Dec 17, 2020

I have never used that parameter type, but there are others that don't work the way you think they would. User macros are in need of TLC for quite some time. It is a shame, but they are not maintaining this very powerful tool, and given the forced move to the cloud, user macros will only be available to data center customers -- larger entities that have resources to program full-blown plugins.

Bill Bailey Community Leader Dec 29, 2020

@Michael AmmannI found this article when researching another topic:

how-to-display-modified-page-dates-in-a-table 

What is interesting is that they are using the confluence content type in a user macro and converting it back into a page object. I think that will solve your problem as once it is an objects, the usual methods can be used.

Let me know if this helps

In our macro we make quite the same as mentioned in this article. But as the link contains the page title, we have the problem that the title is escaped and e.g. the & is replaced by the html entity & If there is no way to avoid this conversion, the page tile has to be decoded again and I found no velocity helper to do this for all cases.

Bill Bailey Community Leader Jan 11, 2021

I think the issue is having page names that include the following reserved characters: ", ', <,>,&.

My suggestion is to build a find/replace function for those five characters.

As workaround I already replaced the &amp; with the & and I will enhance that. I tried to find a more common solution but I found none. 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
7.4.6
TAGS
Community showcase
Published in Confluence Cloud

Get to know the Confluence team!

Go “behind the screen” to meet some of the Confluence Cloud team. In this video series, we tackle some of the hard-hitting questions you never knew you wanted the answer to!  Meet some of the ...

236 views 0 10
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you