Grails 渲染插件 css 问题 [英] Grails rendering plugin css issue

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

问题描述

我刚刚安装了 grails 渲染插件,并想用它来生成 PDF 文件.我创建了简单的模板,但它导出时没有任何 css 样式.如果我只是从 grails 渲染模板,那么页面会在我的 Web 浏览器中显示所有样式.

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

我的模板:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><头><link rel="stylesheet" href="${resource(dir:'css',file:'main.css')}"/><link rel="stylesheet" href="${resource(dir:'css',file:'webui.css')}"/><r:layoutResources/><title>报告</title><身体><div id="内容"><div id="center-container"><h1><g:message code="default.list.label" args="[entityName]"/></h1><表格><头><tr><th class="trip">trip</th></tr></thead><td>${提示}</td></tr></tbody>

而且我的 webui.css 中有样式 .odd,但它没有应用于行.

任何帮助将不胜感激.

Edit1:我发现样式被获取,如果我按以下方式进行:

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

但我不想硬编码应用程序名称(这也是一个基本上下文路径).有没有更好的方法来生成正确的 css 文件链接?

解决方案

尝试将 Config.groovy 中的 grails.serverURL 设置为应用程序 url(例如 grails.serverURL=http://localhost:8080/应用程序名称).该插件通过此设置解析所有相关链接

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屋!

查看全文
相关文章
Java开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆