播放框架:如何获取资产的绝对路径 [英] Play Framework: How to get the absolute path of an asset
问题描述
我的Play应用程序会自动生成一些HTML电子邮件,这些电子邮件当然会引用服务器上的某些图像.由于HTML电子邮件需要完整的URL才能在客户端获取图像,因此我已经在application.conf
中定义了基本URL,然后在视图模板中构建了完整路径.也就是说,有没有办法获取public/images
目录的完整URL,这样我就不再需要其他配置了?
My Play application automatically generates some HTML emails, which of course reference some images on the server. Since HTML emails require full URLs to get the images on the client side, I've defined the base URL in my application.conf
and then build the full path in my view template. That said, is there a way to get the complete URL of the public/images
directory so that I no longer need an additional configuration?
谢谢.
推荐答案
AFAIK,您可以使用反向路由获取资产的完整URL:
AFAIK, you can get the full URL on an asset using reverse routing:
routes.Assets.at("images/anImage.png").absoluteURL()
这篇关于播放框架:如何获取资产的绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!