How to change the route of a static file?

First I had this twitter badge link:

@{'/public/images/twitter-icon.png'/} 

But now I want to show the Twitter-, Facebook- or LinkedIn icon depending on the type. So, I created a FastTag that takes a type as a parameter, and the code looks like this:

 In the view: #{myApp.icon contact.type/} FastTag Java Code: String type = (String) args.get("arg"); out.print("/public/images/" + type + "-icon.png"); 

It works great. But on our build server, we run the application with a uri prefix, like this

 http://ourdomain.com/appname/... 

Obviously / public / images ... will not work here. So I thought that I should ask Router for the correct address. I tried the following without success:

 Router.reverse("/public/images/" + type + "-icon.png"); Router.reverse("/public/"); Router.reverse("staticDir:public"); 

All three results throw a NoRouteFoundException. How can I get the correct route for my icons?

In the routes file, I have a default route for static files

 GET /public/ staticDir:public 
+7
source share
3 answers

I believe this is what you want:

 String imageUrl = Router.reverse(VirtualFile.fromRelativePath("public/images/" + type + "-icon.png")); 
+9
source

Use Router.reverse to create a URL form for one action! perhaps you can define a route that includes the name of your application and the route of one action, for example:

GET / appname / public / TestController.test

now you can use

Router.reverse ("TestController.test")

get the url.

0
source

I think it is better to do something like:

 GET /img/ staticDir:public/images 

And the template is simple:

 out.print("/img/" + type + "-icon.png"); 
0
source

All Articles