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




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


 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Strict // ENhttp://\"> 
< 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>




 < 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"  "">
    <link rel="stylesheet" href="${resource(dir:'css',file:'main.css')}" />
    <link rel="stylesheet" href="${resource(dir:'css',file:'webui.css')}" />
    <div id="content">
        <div id="center-container">
        <h1><g:message code="default.list.label" args="[entityName]" /></h1>
                    <th class="trip">trip</th>
                <tr class="odd">

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


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