Is there a way to encode a url in a speed pattern

Sorry for my ignorance, but I'm new to Velocity and trying to fix something else. I need to encode a url inside a speed pattern. I create a URL and as part of the query string I pass the name of the page the user created. This page may contain special characters, such as "pรป". The URL will look like http://foo.com/page1/jz?page=SpecialChars_รซรฐรป

+4
source share
3 answers

To encode a URL inside a template, you can use:

$esc.url($myUrl)

which is part of EscapeTool .

Note: This required the use of speed jar tools , in addition to speed jar. (It will not throw an exception if you don't have one). Alternatively, you can check the configuration as described here.

+3
source

I know it's late. This is how I solved it today. In the class causing the engine, you can say

 configure("esc",new EscapeTool()); context.put("url", "http://www.google.com"); 

Now in the template you can say

$ esc.url ($ URL)

+1
source

I just did not want to use EscapeTool in speed for url encoding. Therefore, here I got the solution -

you can use $ httpUtil.decodeURL ($ siteURL) / $ httpUtil.encodeURL ($ siteURL) to encode the URL in speed

Alternatively, you can use $htmlUtil.escapeAttribute() to escape text / html Content in Velocity.

$htmlUtil.escapeAttribute($refSiteName)

-1
source

Source: https://habr.com/ru/post/1305178/


All Articles