Widget Construction Tutorial

This section provides an example of how to build a phpHtmlLib widget that can be used by other folks that use phpHtmlLib
To see some of widgets that come with phpHtmlLib Go here

What is a Widget?

A widget is just a functional block of html that can be reused in many places on a single page or application. I have built a few widgets that I use to do some common things for some of my websites/applications that I build. Most of them are navigational widgets such as the TextCSSNav and the NavTable widgets. These both provied a navigational element that is easy to use/reuse.

Why Use Widgets?

The most obvious answer is write once, use many. They boil down to the same reasons why I use objects to do html/pages/applications in the first place.
  • Easy to use
  • Ease of maintenance in the long run
  • Fix a bug? All pages that use it get the fix
  • Consistency amung pages/applications
  • Code Reuse
  • Code Reuse
  • Code Reuse


Since Widgets are by design supposed to be reusable in many places of a page, and on many pages on a site/application, making sure the html it outputs is rock solid amung your supported browsers can be a pain. But that is true for any html code you write. So they do take some time to get right, and provide an easy to use API. But once you are done, its just awesome to reuse, reuse, reuse.