2005-09-16

Subterranean exploration, part 2 or What's a Widget?

Now that I have the attention of all you Thornton Melon fans, it's time to once again illuminate our electric torches and brandish our pickaxes in search of the latest chunky cured pork products from the Subway project. Today we're going to talk about widgets

Calm down! Calm down. It's okay. There's no danger here. Unlike the terrifying toe eating widgets of the Gobi dessert, Subway's variety are friendly. They're small, cuddly and unicorn-like in their ability to slowly drain impure thoughts from your brains.

Subway's widgets are small bits of view code available in the widget namespace. This means that your views can include those widgets whenever they are needed. The widgets themselves live in your application's widget directory and are, just like Subway's views, Cheetah templates. Here's an example widget that I'm fond of:


#if 'notice' in $flash
<div class="notice">
$escape($flash.notice)
</div>
#end if


That's Subway's notice.html widget which is used for web status notification. Whenever you need it, just drop it into your view using
$widget.notice
and you're all set. If you need to you can also pass arguments to your widgets using normal Python syntax.

My friend, if you like widgets, and I mean really like widgets, then go read Subway's How-to page on them right now!

No comments: