When the page object needs to locate a template to use as a layout or page section, it locates the template using a search path that allows for sharing and inheritance of templates as well as specialization for a specific controller or action.
When Woof! needs to retrieve a page section with name SECTION for responding to a client request with a URL that is mapped to a controller CONTROLLER and action ACTION, it follows the search procedure below. (When looking for a page layout template, SECTION will be layout.)
The above algorithm is slightly modified when the client indicates a preferred language. Details are given in Language-Specific Page Templates.
The above search mechanism for templates allows layouts and page sections to be easily shared and inherited as illustrated by the examples below.
The examples assume the following layout is being used by the application:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html>
<head>
<title>Example Layout</title>
</head>
<body>
% if {[page fetch header content]} {
$content
<hr/>
% }
% if {[page fetch main content]} {
$content
% }
% if {[page exists footer content]} {
<hr/>
$content
% }
</body>
</html>
Assuming the above layout, a common header page section for the entire site can be defined by the contents of the file app/controllers/views/header.wtf. All URL's for the site will automatically show its content wherever the layout file inserts the page section named header. A different header section can be defined for a particular controller, say blogs, by creating the file app/controllers/views/blogs-header.wtf. The command
page fetch header content
in the layout will then fetch the header section content from this file for all URL's for the blogs controller and from app/controllers/views/header.wtf for all other controllers.
As another example, imagine the website has a separate module, site::admin, that is used for managing the website itself. So the URL http://www.mywebsite.com/site/admin/user/show (for example) would be mapped to the show action method in the controller user (implemented in class UserController) in the site::admin module. To render the header page section, Woof! will look for templates in the following order:
Note that when searching up the directory hierarchy, Woof! only uses the section name and does not look for the controller and action specific templates (such as user-show-header.wtf or user-header.wtf). This is by design as it does not make sense for a file specific for a controller and/or action to show up outside the controller content directory.
Woof! Version: 0.4, Server: Apache, Interface: CGI, Tcl: 8.6b1.1