开发者

Grails display gsp inside div

Hey. Imagine i have two separate gsp pages with diferent css formatting (with name conflicts between two). And i want to "display" or render one page with its ows formatation inside a div in the other page. Imagining this scenario:

page1.gsp

...
...
<div id="here"></div>
...
...

page2.gsp

Hello there!

I want my final page to be:

    ...
    ...
    Hello there!
    ...
    ...

Is 开发者_如何学JAVAit possible to do that?


Yes use the g:render tag and create a "fragment" page to contain your content.

then use the g:render tag to pull it in.

Refer to the documentation or tutorials for more detail on this.


This is very similar to a question I posted a couple of days ago: Can I display an inner dive with an independent stylesheet?


Is this something you want to work for every page? (Like a layout?)

If that is the case, use SiteMesh (built in already)

{app}/grails-app/views/layouts/mylayout.gsp

<html>
<head>
<g:layoutTitle default="My Application" />
<link rel="stylesheet" href="${resource(dir:'css',file:'layout.css')}" />
<g:layoutHead />
</head>
<body>
<div id="here"><g:layoutBody /></div>
</body>
</html>

{app}/grails-app/views/{somefolder}/page1.gsp

<html>
  <head>
    <meta name="layout" content="mylayout" />
<link rel="stylesheet" href="${resource(dir:'css',file:'page1.css')}" />
  </head>
  <body>
    Hello There!!!!
  </body>
</html>

If you already have that, and are just looking at breaking up you pages and keeping them DRY..

{app}/grails-app/views/{somefolder}/page1.gsp

<html>
  <head>
    <meta name="layout" content="yourLayout" />
<link rel="stylesheet" href="${resource(dir:'css',file:'page1.css')}" />
  </head>
  <body>
    <div id="here2"><g:render template="page2" model="[foo:'bar']"/></div>
  </body>
</html>

* The Model property of render is optional, but works for passing data to the template to be rendered

{app}/grails-app/views/{somefolder}/_page2.gsp

* Notice the "_" before the gsp name. (Convention for Template pages)

Hello There

Checkout the documentation for render and templating

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜