Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to encode a URL in velocity template

Excuse my ignorance but I am new to Velocity and trying to fix someone else's problem. I need to encode a URL inside the velocity template. I create a url and as part of the query string I pass in a page name a user created. This page can contain special characters like ëðû. The url would look like http://foo.com/page1/jz?page=SpecialChars_ëðû

like image 692
fermatthrm2 Avatar asked Oct 15 '22 07:10

fermatthrm2


2 Answers

To encode URL inside a template you can use:

$esc.url($myUrl)

which is a part of EscapeTool.

Note: This required to use velocity tools jar, in addition to the velocity jar. (It will not throw exception if you will not have it). Moreover, you might want to check you configuration, as describes here

like image 162
serg Avatar answered Oct 18 '22 22:10

serg


I know it is late. Here is how I solved this today. In the class calling the engine, you could say

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

Now in the template you could say

$esc.url($url)

like image 41
sreeprasad Avatar answered Oct 18 '22 21:10

sreeprasad