Grails呈现插件css问题 [英] Grails rendering plugin css issue

查看:89
本文介绍了Grails呈现插件css问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚安装了grails渲染插件,并希望将其用于生成PDF文件。我创建了简单的模板,但它没有任何CSS样式导出。如果我只是从grails呈现模板,那么页面会在我的Web浏览器中显示所有样式。



所以,我的问题是 - 如何在PDF生成过程中正确包含CSS文件?



我的模板:

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Strict // ENhttp:// www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> 
< html>
< head>
< link rel =stylesheethref =$ {resource(dir:'css',file:'webui.css')}/>
< r:layoutResources />
< title>报告< / title>
< / head>
< body>
< div id =content>
< div id =center-container>
< h1>< g:message code =default.list.labelargs =[entityName]/>< / h1>
< table>
< thead>
< tr>
< th class =trip> trip< / th>
< / tr>
< / thead>
< tbody>
< tr class =odd>
< td>
$ {tip}
< / td>
< / tr>
< / tbody>
< / table>
< / div>
< / div>
< / body>
< / html>

我的webui.css中有样式.odd,但它不适用于该行。



任何帮助将不胜感激。



Edit1:我发现样式被抓取,如果我这样做如下所示:

 < link rel =stylesheethref =my_appname $ {resource(dir:'css' ,file:'main.css')}/> 

但我不想硬编码应用程序名称(这也是一个基本的上下文路径)。有没有更好的方法来生成正确的链接到一个CSS文件?尝试设置 grails.serverURL 将Config.groovy中的添加到应用程序url(例如grails.serverURL = http:// localhost:8080 / appname)。该插件通过此设置解析所有相关链接


I've just installed grails rendering plugin and would like to use it for generating PDF files. I've created simple template, but it is exported without any css styles. If I simply render template from grails, then page appears with all styles in my web browser.

So, my question is - how to correctly include CSS file during PDF generation process?

My template:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
    <link rel="stylesheet" href="${resource(dir:'css',file:'main.css')}" />
    <link rel="stylesheet" href="${resource(dir:'css',file:'webui.css')}" />
    <r:layoutResources/>
    <title>Report</title>
</head>
<body>
    <div id="content">
        <div id="center-container">
        <h1><g:message code="default.list.label" args="[entityName]" /></h1>
        <table>
            <thead>
                <tr>
                    <th class="trip">trip</th>
                </tr>
            </thead>
            <tbody>
                <tr class="odd">
                    <td>
                        ${tip}
                    </td>
                </tr>
            </tbody>
        </table>
</div>
    </div>
</body>
</html>

And I have style .odd in my webui.css, but it is not applied on the row.

Any help would be appreciated.

Edit1: I found out that styles are fetched, if I do it in the following way:

<link rel="stylesheet" href="my_appname${resource(dir:'css',file:'main.css')}" />

But I don't want to hardcode application name (this is also a base context path). Is there a better way to generate proper link to a css file?

解决方案

Try setting grails.serverURL in Config.groovy to the app url (ex. grails.serverURL=http://localhost:8080/appname). The plugin resolves all relative links via this setting

这篇关于Grails呈现插件css问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆