Chapter 13.2.2. Creating Custom Tags with py:match

You aren’t limited to matching existing tag names. You can use py:match to create your own custom tag libraries. This means you can add py:match='item.tag == "sidebar"' which automatically adds a sidebar to your page whenever the page has a <sidebar> tag.

In fact, there’s nothing new to learn about how to create custom tags. You just use py:match in the same way we did before, but now you match against your own newly created tag name. Then, whenever you want that match template added to your page, just use the tag.

Because match templates have access to the matching element, you can easily define custom tag attributes that are processed by the match template to give you the custom tag behaviors. ...

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.