0

I'm looking for a way to url decode a string variable on Freemarker.

For example, consider the following string: attr=hello+world%3F . Expected result: hello world?

Any simple way to get this result? somewhat like ${attr?urlDecode}? I could not find anything online.

Thanks.

Amir
  • 161
  • 3
  • 15
  • I was looking for same answer, this is most probably solved here: https://stackoverflow.com/questions/43455730/in-freemarker-how-to-convert-a-string-to-utf-8-encoding – Ernedar Mar 30 '23 at 14:06

2 Answers2

1

As mentioned above, FreeMarker only has built in support for URL encoding, not decoding. You can however solve this by creating your own directive for URI-decoding.

Something like this: https://gist.github.com/lazee/285d206470fb6076d262

Here is a small test class that shows you how you can add the directive as a shared variable, and how to use it in a template: https://gist.github.com/lazee/f5c524b3c7bebf68955e

Jakob Vad Nielsen
  • 722
  • 1
  • 7
  • 13
0

There's no such function built in (2.3.23).

In what scenario is it needed?

ddekany
  • 29,656
  • 4
  • 57
  • 64