Announcement Announcement Module
Collapse
No announcement yet.
render method - controller vs GSP Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • render method - controller vs GSP

    I'm implementing a context sensitive help system for my Grails app. The help page is fire from an action as follows:

    Code:
    def help = {
            def helpText = "Help is on the way";
            render(template: "/layouts/help", model: [helpText: helpText])
        }
    The template (_help.gsp) is just the HTML to display the content, which I'm going to layout on the current page with CSS, so it's really simple right now:

    Code:
    <div id='help'><p>${helpText}</p></div>
    Here's the problem: the render method in the controller does not behave the way a render in a GSP does. In a GSP, the following:

    Code:
    <g:render template="/layouts/help"/>
    will lay the content out inline - that is, on the same page.

    The render in the controller loads a new page.

    How do I get a controller's render to display inline?

    Brian

  • #2
    You have a couple of options:

    <g:include controller="..." action="help"/>

    or load the HTML fragment using AJAX.

    Hope that helps,

    Peter

    Comment


    • #3
      Re : Alternative solution

      Peter,
      Another solution he might be looking for is to return the raw html from the tag.

      ie.. instead of :


      Code:
       def help = {
              def helpText = "Help is on the way";
              render(template: "/layouts/help", model: [helpText: helpText])
          }
      he could do

      Code:
      def help = {
              def helpText = "Help is on the way";
              g.render(template: "/layouts/help", model: [helpText: helpText])
          }
      notice the 'g.' in front of render call...

      I had a very similar problem recently where i needed the output rather than to have it write to the out stream...

      Comment

      Working...
      X