Parse and manipulate URLs in velocity

36 views
Skip to first unread message

Dave Hess

unread,
Jul 31, 2023, 2:21:34 PM7/31/23
to dotCMS User Group
Is these a view tool or utility class that can be used in Velocity to parse and manipulate URLs? I want to be able to change the hostname or URL path in a URL in my velocity template.

John Michael Thomas

unread,
Aug 2, 2023, 8:44:19 AM8/2/23
to dotCMS User Group
I don't know of any methods specifically related to URLs, though you can check the Javadocs for the UtilMethods viewtool to see if there's anything in there.

But Velocity is just a thin layer over Java, and Velocity objects are just Java objects under the covers.  So, you can use Java string methods, including string replace.  This would look something like #set( $newString = $oldString.replace("/oldPart/", "/newPart/") )

Disclaimer: I make no guarantee that the above syntax is correct, since I haven't done this in quite a while.  But it will should something like that.

Reply all
Reply to author
Forward
0 new messages