Chapter 13.2. Beyond the Basics: Keeping Your Templates DRY (Don’t Repeat Yourself)

Most web applications have common headers, footers, sidebars, and other repeated page elements. Sometimes these are static, and sometimes they are dynamic. But unless your template system provides mechanisms for handling this kind of thing, you are going to end up with a lot of repeated code in various page templates. And repeated code makes future changes harder, turns finding all occurrences of a bug into a tedious and complex process, and can introduce subtle bugs.

You’ve already seen one of the mechanisms Kid provides for factoring similar template code out into named template functions. And if that’s all there was, it would be enough to keep your code ...

Get Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.