The page class allows you to programmatically create the shell of an XHTML page with special consideration given to the ability to dynamic define elements of that page that are relevant to SEO.
I understand that some may question the need for such a class but in those times where I needed to either cache a whole page, or I needed to have fine granular control over page titles, meta tags, and the like without having to poke around numerous template files, I have found this class to be very useful over the years.
Download or view the source code by clicking the appropriate link below.
At its simplest, you only need to include and instantiate the class, set the contents of the page and call the display() method as shown below:
The code above will produce the output below. You can chose to call the 'display()' method which will print the output to the browser, or you can call the 'fetch()' method which will return the page as a string which you can then cache or do with the returned string whatever you want.
There are a number of methods available for setting meta tag information, comments, doctype, the CSS Id and CSS class of the page, clearing those attributes and more. See the source code to view all options. Below is an example of how you might typically use the class in real life:
The above will produce the output below.
The class has also been fitted to support fluent interfaces if you prefer to use them. In other words you can use the class also as follows:
There are currently no comments on this article. You could be the first!