• dashboard
  • " />
    • dashboard
    • " />
      • dashboard
      • "/>
        DEVHIDE
        • Home (current)
        • About
        • Contact
        • Cookie
        • Home (current)
        • About
        • Contact
        • Cookie
        • Disclaimer
        • Privacy
        • TOS
        Login Or Sign up

        Grails Layouts - Kind of a Nested Layout Problem, Conditional Content

        820 Views Asked by Gregg At 28 February 2011 at 20:08 2025-12-11T10:54:13.613000

        I have the following (simplified) layout:

        <header>
          ... more stuff here
          <nav id="nav">
            <div class="content_wrapper">
              <ul id="menu">
                <li>dashboard</li>
              </ul>
            </div>
          </nav>
        </header>
        <div id="main_content">
          <div class="content_wrapper">
            <g:layoutBody/>
          </div>
        </div>
        

        My problem is that the "menu" nav is dependent on what is rendered in the layoutBody. Not only will the text "dashboard" change to "login", "support", etc but on some pages there are buttons, links, etc. Is there any way in Grails, without changing the layout of the page, to dynamically render this NAV element based on the layoutBody? I've read the docs including the content block section, but they don't solve the problem because they are still pre-determined in the main layout.

        grails layout sitemesh
        Original Q&A
        1

        There are 1 best solutions below

        1
        fabien7474 fabien7474 On 28 February 2011 at 22:00 BEST ANSWER

        I have the same problem on my grails webapp. Here is the way I have solved it. In your layout:

        <nav id="nav">
            <div class="content_wrapper">
              <ul id="menu">
                //Here you can insert whatever you have in all your pages
                //Then below you can insert custom content depending on main body
                <li><g:pageProperty name="page.nav-content"/></li>
              </ul>
            </div>
        </nav>
        

        Then in your main views (like home.gsp) requiring additional modules (like login module), you can include something like:

        <content tag="nav-content">
           <g:include controller="nav" action="login"/>
        </content>
        

        Related Questions in GRAILS

        • No such property: id for class: java.lang.String
        • Using like to non-string columns in Grails
        • How to convert object reference that are in string form to that refrence class object?
        • Restrict access to java-melody monitoring url
        • Intercepting springsecurity behavior in grails
        • Sort a Grails Domain list using a column index instead of column name
        • Using service beans and dependency Injection in Geb Functional Tests
        • how to create a pdf editor for grails
        • Remove method of the List is not working
        • Grails query based on Date
        • Unit tests fail to run after upgrade from grails 2.3 to 2.5
        • GGTS Classpath won't recognize folder on classpath after gradle eclipse
        • Grails 2.4.4. hierarchical domain structure: find
        • change input field value via javascript in grails
        • Create skinny War file using Maven in Mavenized Grails

        Related Questions in LAYOUT

        • SAS- Defining Page Breaks inside Macro
        • How to receive onConfigurationChanged events (Android SDK)
        • Get error in Swing java - IllegalArgumentException
        • Setting an onClick listener to a layout
        • CSS two columns without specific widths
        • RecyclerView gets pushed down when returned to activity
        • Prevent DIV overflowing container using flex layout
        • Set background - centered and not stretched
        • Plug-in: com.android.ide.eclipse.adt error
        • Possible to change border position based on adjacent blocks in CSS?
        • last Relative layout not displaying properly in android xml
        • Automatically Adjust the Font Size of the Text in order to fit in a Div
        • Setting the layout of the swiped card in RecyclerView using ItemTouchHelper
        • How to create one page app on Windows Phone
        • Allow absolutely positioned child to render outside parent with overflow: hidden

        Related Questions in SITEMESH

        • Spring Servlet and Spring security filter chain Url Patterns
        • Cannot execute body onload function in <body> from Sitemesh
        • Problem excluding pages with siteMesh Struts2 Tomcat 6
        • Render a page in grails without html and body tag
        • Does the Grails undocumented method ifPageProperty actually work?
        • Spring Framework Error Controller with Freemarker
        • Grails Layouts - Kind of a Nested Layout Problem, Conditional Content
        • Spring security 3.1 sitemesh not decorating page
        • grails eclipse - Unknown tag(r:require)
        • Sitemesh: decorator.xml using .properties file
        • sitemesh 3 safe to use in production?
        • Getting started with Grails Resources Plugin
        • How to use sitemesh effectively in webapplication
        • Sitemesh spring:message not recognized in template
        • How to deal with zTree under Spring MVC and sitemesh?

        Trending Questions

        • UIImageView Frame Doesn't Reflect Constraints
        • Is it possible to use adb commands to click on a view by finding its ID?
        • How to create a new web character symbol recognizable by html/javascript?
        • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
        • Heap Gives Page Fault
        • Connect ffmpeg to Visual Studio 2008
        • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
        • How to avoid default initialization of objects in std::vector?
        • second argument of the command line arguments in a format other than char** argv or char* argv[]
        • How to improve efficiency of algorithm which generates next lexicographic permutation?
        • Navigating to the another actvity app getting crash in android
        • How to read the particular message format in android and store in sqlite database?
        • Resetting inventory status after order is cancelled
        • Efficiently compute powers of X in SSE/AVX
        • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

        Popular # Hahtags

        javascript python java c# php android html jquery c++ css ios sql mysql r reactjs

        Popular Questions

        • How do I undo the most recent local commits in Git?
        • How can I remove a specific item from an array in JavaScript?
        • How do I delete a Git branch locally and remotely?
        • Find all files containing a specific text (string) on Linux?
        • How do I revert a Git repository to a previous commit?
        • How do I create an HTML button that acts like a link?
        • How do I check out a remote Git branch?
        • How do I force "git pull" to overwrite local files?
        • How do I list all files of a directory?
        • How to check whether a string contains a substring in JavaScript?
        • How do I redirect to another webpage?
        • How can I iterate over rows in a Pandas DataFrame?
        • How do I convert a String to an int in Java?
        • Does Python have a string 'contains' substring method?
        • How do I check if a string contains a specific word?
        .

        Copyright © 2021 Jogjafile Inc.

        • Disclaimer
        • Privacy
        • TOS
        • Homegardensmart
        • Math
        • Aftereffectstemplates