grails - grails 2.4.0 上的 Assets 标签

标签 grails

我在 2.4.0 版本上开始了一个新的 grails 项目。
在这个版本中,grails-app 文件夹中添加了子文件夹asset,以便于访问js、css、图像等。

但是,我无法访问子文件夹,例如,我的文件夹结构如下:
grails-app/assets/stylesheets/fonts/font.css
然后当我使用<asset:stylesheet src="font.css"/> (注意 font.css 放在 stylesheets 文件夹中)

但是当我尝试这个时,没有找到 font.css。

<asset:stylesheet src="/fonts/font.css"/>

请建议另一种使用 Assets 标签访问子文件夹的方法。

最佳答案

不要直接链接到子文件夹。使用application.cssgrails-app/assets/stylesheets .

application.css告诉 Assets 插件包括你的font.css通过添加以下内容:

/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS file within this directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require fonts/font.css
*= require self
*/

在您的布局 (GSP) 中使用 application.css像这样。
<asset:stylesheet src="application.css"/>

这将解决您的问题。

关于grails - grails 2.4.0 上的 Assets 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24321211/

相关文章:

grails - 我该怎么办:在grails g:select中需要=“false”?

Grails httpconnection 到自签名证书

grails - beforeDelete() 中的服务访问

javascript - 我如何从 JavaScript 和 Grails 访问变量?

mysql - Grails/Hibernate 数据库在负载 : Unable to connect (even when pooling) 下崩溃

Grails:关闭 Controller 操作的 Codenarc NoDef 规则

grails question (sample 1 of Grails To Action book) Controller 和服务问题

grails - 域中的日期字段和g:textField标记在Grails中不起作用

grails - 将log4j.xml放在Grails应用程序中的哪里?

spring - grails +单例服务,用于将对象保存到数据库以供云应用程序