title: How does Grails know to apply a "layout" to pages it renders?
body: <p>I've been going through the book "The Definitive Guide to Grails" (Rocher/Brown) and in Chapter 04, this mysterious thing called a "layout" just appeared with no explanation. (And there's no "layout" in the index. As far as I know, it's never explained.)</p>
  
  <p>How does the system know to "inherit" the pages from layout/main.gsp? There's nothing about "layouts" in the index, and it seems to have just appeared.</p>
  
  <p>On their sample app, a simple store site, the URL mappings for the / homepage say</p>
  
  <pre><code>  "/"(controller:"store")
  </code></pre>
  
  <p>and store controller's empty "index" closure</p>
  
  <pre><code>package com.g2one.gtunes
  
  class StoreController {
  
      def index = {
      }
  }
  </code></pre>
  
  <p>simply tells it to render store/index.gsp</p>
  
  <p>The store/index.gsp just has a few lines of HTML; no layout gets included with any directive</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-type" content="text/html; charset=utf-8"&gt;
          &lt;meta name="layout" content="main"&gt;
          &lt;title&gt;gTunes Store&lt;/title&gt;
          &lt;g:javascript library="prototype"&gt;&lt;/g:javascript&gt;
      &lt;/head&gt;
      &lt;body id="body"&gt;
          &lt;h1&gt;Your online music store and storage service!&lt;/h1&gt;
          &lt;p&gt;Manage your own library, browse music and purchase new tracks as they become available&lt;/p&gt;
      &lt;/body&gt; 
  &lt;/html&gt;
  </code></pre>
  
  <p>When I run the sample the page shown for "/" isn't just this simple HTML, it's the contents of "layouts/main.gsp" with this information magically inserted inside it.</p>
  
  <p>I don't see how the information in layout/main.gsp gets applied to the page, how the elements get mixed together. I've been following through the book page by page and this functionality just "appeared" with no explanation.</p>