Content blocks
Content blocks are a way to mark blocks of content for later use in a Sitemesh template. This gives you finer-grained control over how to lay out the page. In your Sitemesh template, you can arrange components within the body, instead of treating the entire body as an indivisible block. To define a block, enclose it in <content> tags, with tag=name the name you'll use to refer to it later:
Then you can reference these blocks in your Sitemesh template like this:
This is very useful because it allows you define the layout for your pages in one (or a few) Sitemesh templates, instead of in multiple jsp pages. Your jsp pages just output the content, and let the Sitemesh template(s) handle layout.
For example, say you have dozens of jsp page that look like this:
This page defines four content blocks: header, nav, bodyContent, and portlets. To create a page layout that looks like this:
| header goes here |
| navbar goes here |
content body goes here |
portlets go here |
create a Sitemesh template like this:
But what happens someone decides that page is too wide, and the portlets should go below the content instead of on the right?
| header goes here |
| navbar goes here |
content body goes here |
| portlets go here |
If you'd put the layout in the jsp files, you'd have to change it in every file. But with the layout in the Sitemesh template, you only need to change the single template file.
Change the Sitemesh template to this, and you're done: