Reputation: 28893
Say I'm passing a list of image urls from the server to the frontend.
images/
image1.jpg
image2.jpg
image3.jpg
Now I'm just listing the file names, but I need to reference the absolute path (/application/images/image1.jpg
). Basically the equivalent of ${resource}
server side.
Upvotes: 0
Views: 9270
Reputation: 2108
for reading file (cvs, xml, img ,...) from controller I use:
def csv = grailsAttributes.getApplicationContext().getResource("/data/jak.csv").getFile()
Regards Tom
Upvotes: 3
Reputation: 649
You can call this code in your controller:
String pathToImage1 = g.resource(dir: 'images', file: 'image1.jpg', absolute: true)
Flag 'absolute' may be skipped.
Upvotes: 6
Reputation: 75681
You can call tags from controllers - see http://grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html#6.2.2.6%20Tags%20as%20Method%20Calls
Upvotes: 1