How can I avoid html encoding for Parameters in user macros
Asked by Michael Ammann:

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 \&amp; 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?


Answers:
author: Bill Bailey
body: is your parameter type set to "type=confluence-content"? That is supposed to allow a user to run a match to existing content.

comments: author: Michael Ammann
body: 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.


author: Bill Bailey
body: 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?


author: Bill Bailey
body: 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).


author: Michael Ammann
body: 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.


author: Bill Bailey
body: 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.


author: Bill Bailey
body: [@Michael Ammann](/t5/user/viewprofilepage/user-id/593617)I found this article when researching another topic:

[how-to-display-modified-page-dates-in-a-table](https://confluence.atlassian.com/confkb/how-to-display-modified-page-dates-in-a-table-1005791769.html)

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


author: Michael Ammann
body: 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 \&amp; 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.


author: Bill Bailey
body: 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.


author: Michael Ammann
body: 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.


Tags: confluence-server

server