Page sections
A page section is the HTML content of a specific area within a Web page, for example, the header area. Page sections may be generated by a controller method, or from a template containing a mixture of HTML content and Tcl code.
The page object
By convention, layouts expect to retrieve their page sections from the page object, of class Page, that is created by the controller for every request. This object will return the raw HTML content of a specified page section through its fetch method. For example, the following is a fragment from a layout template.
% if {[page fetch header header_content]} { <hr/>$header_content<hr/> % }
If the page object has a header section defined, or can generate one, it returns the content of that section in header_content and returns true. Otherwise it returns false. The layout template fragment conditionally includes that content, braced by horizontal rules.
The page object may be populated with page sections in one of two ways.
- When a layout invokes the fetch method to retrieve a page section that has not yet been defined, the page object will search the file system for a suitable template from which the page section might be generated. This is the recommended way of producing a page section wherein the template provides the presentation for the page separately from the action method.
- Alternatively, an action method may directly store the HTML fragment for a page section in which case the fetch method simply returns the stored content for the section
The following sections describe both these methods.