13.3. Bringing It All TogetherSo, let's take a look at the master.kid file from a freshly created project. This contains a single match template that displays login information, Flash messages, and the TurboGears logo. Chances are you'll want to keep something like this to have Flash and Identity messages automatically appear on your pages, but you'll likely want to edit the CSS references and add additional match templates: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ TR/xhtml1/DTD/xhtml1-transitional.dtd"> <?python import sitetemplate ?> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#" py: extends="sitetemplate"> <head py:match="item.tag=='{http://www.w3.org/1999/xhtml}head'" py:attrs="item. items()"> <meta content="text/html; charset=UTF-8" http-equiv="content-type" py:replace="''"/> <title py:replace="''">Your title goes here</title> <meta py:replace="item[:]"/> <style type="text/css"> #pageLogin { font-size: 10px; font-family: verdana; text-align: right; } </style> </head> <body py:match="item.tag=='{http://www.w3.org/1999/xhtml}body'" py:attrs="item. items()"> <div py:if="tg.config('identity.on',False) and not 'logging_in' in locals()" > <span py:if="tg.identity.anonymous"> <a href="/login">Login</a> </span> <span py:if="not tg.identity.anonymous"> Welcome ${tg.identity.user.display_name}. <a href="/logout">Logout</a> </span> </div> <div py:if="tg_flash" py:content="tg_flash"></div> <div py:replace="[item.text]+item[:]"/> <p align="center"><img src="/books/4/370/1/html/2//static/images/tg_under_the_hood.png" alt="TurboGears under the hood"/></p> </body> </html> Here are a few things you might want to look for in the above code:
The master.kid page is written so that it could be opened directly in your browser or image-editing tool without the need to preprocess it with Kid. This way, designers have something they can work with on the "master" template. The first py:match element matches the header of the incoming page. But if you look inside it, all the tags use py:replace to replace themselves with empty strings. This is what makes it possible to view this page directly in a browser. And at the end, we have a py:replace=item[:] that takes all the head subelements from the original page, and puts them back into the match template's output page. With a basic understanding of what is happening in this page, you should be able to modify it to add headers, footers, sidebars, or just about anything you need on every page of your TurboGears project. |