Reputation: 169
I wanted to implement @routes.Assets.versioned("com/images/image.png") using java class currently I'm using the above in my scala.html file for an image which return the path for the image. Now i wanted to call a utils class method like @utils.UtilClass.getImage("com/images/image.png") so that i wanted to append a CDN basepath to the versionised image path that i get from @routes.Assets.versioned() for that i need to replicate the functionality of routes.Assets.versioned() in java class, I tried Assets.versioned("", Asset) which is returning an Action object and dint know how to extract the versioned path from the object. Any help is appreciated.
Upvotes: 2
Views: 252
Reputation: 8263
It's easy:
String url = 'images/favicon.png';
String versionedUrl = controllers.routes.Assets.versioned(new controllers.Assets.Asset(url)).toString()
For example I have such method in my Handlebars helpers for the Play:
/**
* Do the same as "@routes.Assets.versioned" in Twirl.
*
* @param url
* relative path to the asset
* @return actual path to the asset
*/
public static CharSequence asset(final String url) {
return controllers.routes.Assets.versioned(new controllers.Assets.Asset(url)).toString();
}
Upvotes: 2