0

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 it possible to do that?

John
  • 259
  • 8
  • 19

3 Answers3

0

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.

Dave G
  • 9,639
  • 36
  • 41
0

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

Community
  • 1
  • 1
Jim Norman
  • 751
  • 8
  • 28
0

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

Nick Larson
  • 547
  • 3
  • 7