February 04, 2004

Index page is now PHP

One of the great features of Moveable type is that it builds static pages out of the content stored in the database. After an update to a news item or blog you "rebuild" your sites pages using the templates provided. This is a great performance enhancer for your site. If you have a lot of traffic serving up static pages is a lot kinder on your server than serving up dynamic pages that grab information from a database.

Still, you may want to include some dynamic content and add some PHP functionality to your home page. But if MT is building static pages how can you get that functionality. Simple. MT allows you to specify which file to build when it does its "rebuild". So instead of having the template of the Main Index create a file called Index.html - you can tell it to build a page called Index.php.

This is what I have done here. Its a best of both worlds situation really. I can include some lightweight (low server load) php functionality to my index page and still leave the heavier lifting of database access to MT on an AS NEEDED basis when I re-build the site.

Of course the template file that MT uses to do the re-build must now include the PHP code that I want to include. Having PHP code that changes regularly written into a template file doesn't seem to make much sense though. Template files should be initially modified and then left alone. After all that is the power of the template file - build the template once and never have to worry about it until you decide to make a major change.

Still, there is an easy way around this. In your template file all you really need to do is add a few simple PHP include statements that point to other files that you can modify and update freely without touching the template itself.

Done and Done.

As of right now this is what is going on here at this site. I can still harness the power of the templating system. I can still reduce the stress on the server by having the majority of the page's content pre-built. AND I can include some PHP code for some specialty features. The best of all worlds.

andre

Posted by andre at February 4, 2004 03:11 AM