Search code examples
grailslayout

using 3 layouts on same gsp page


this is edit of my question that was first how to apply 2 layouts in the same gsp page but now i got problem with 3 layouts :) :

I am fairly new to all that css and layout stuff and i'm using grails 2.0 version i have the following moduls in my problem:
1. main.gsp layout which basically have a nice header with company logo for all pages.
2. mainTabPanle.gsp layouts which basically contain some main tabs all pages should have 3. reportTab.gsp layout which basically contain nice report tabs and short javascript code to manipulate chosen tab color that all reports gsp pages should have.

what i am trying to do is to use this reportTab layout in all the reports gsp pages.

so this is what i got so far:

main.gsp:

<!doctype html>  
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="${resource(dir: 'css', file: 'main.css')}"type="text/css">
<g:layoutHead/>
<r:layoutResources />
</head>
<body style="height:100%">
<div>some nice header in here </div>
<g:layoutBody/>
<r:layoutResources />
</body>
</html>

mainTabPanle.gsp (also located in layout folder)

<g:applyLayout name="main">    
<!doctype html> 
<html> 
<head>
<g:layoutHead/>
<r:layoutResources />
</head>
<body>
<div>some main tabs here </div> 
<g:layoutBody/>
</body>
<script type="text/javascript">
//script to manipulate main tabs    
</script>
<r:layoutResources />
</body>
</html>
</g:applyLayout>

reportTabPanel.gsp:

<g:applyLayout name="mainTabPanel">    
<!doctype html> 
<html> 
<head>
<g:layoutHead/>
<r:layoutResources />
</head>
<body>
<div>some reports tab panel </div>  
<g:layoutBody/>
</body>
<script type="text/javascript">
//some script to manipulate report tab item
</script>
<r:layoutResources />
</body>
</html>
</g:applyLayout>

and now im using in moneyreport.gsp header the following line:

<meta name="layout" content="reportTabPanel" />

what i want to see is the nice header and the maintabsPanel and the reportTabPanel but all i see is the body of moneyreport.gsp

the weird thing is that if i use this:

<meta name="layout" content="mainTabPanel" />

inside moneyreport.gsp i see mainTab and the body of moneyreport.gsp as expected.

what am i doing wrong? i cannot use 3 layout on the same page?

thanks for your help guys ...


Solution

  • You can apply 2 layouts on the same page. In order to apply a different layout in a layout file, you need to use the applyLayout tag. Your reportTab should be something like this:

    <g:applyLayout name="main">    
    <!doctype html>  
    <head>
    <g:layoutHead/>
    <r:layoutResources />
    </head>
    <body>
    <div> some nice tabs here </div>
    <g:layoutBody/>
    </body>
    <script type="text/javascript">
    few line script handling chosen tab color in here
    </script>
    <r:layoutResources />
    </body>
    </html>
    </g:applyLayout>