Dynamic Pages

January 13, 2003 - updated February 8, 2006

While MovableType makes it easy to quickly update your web site, all it really does is build static pages. The content in these pages is usually fixed once they are (re)built.

Instead of having static HTML pages, you can also have dynamic pages, for example showing the current time or tempterature, or displaying a different picture every time they are loaded. In order to have dynamic content, you must go beyond simple HTML.

There are many different ways to create dynamic pages. Some of the most common ones are Server Side Includes (SSI) and PHP which are both processed on the server, and JavaScript which is executed in the browser. There are meny great resources on the Internet that can help you learn these scripting languages, so I’m only going to describe how you would use them with MovableType.

PHP

PHP is a powerful scripting language that allows you to easily create dynamic documents on the server. Documentation for the language can be found on the php.net web site.

The following is an example of PHP code embedded in a document. It displays the current date and time:

Current date and time is <?php echo date("D M j G:i:s Y"); ?>

PHP Server Requirements

PHP documents are executed on the server, and your web server must be configured to support them. Most hosting providers these days have PHP support. The web server recognizes PHP documents by their file extension, which is usually .php. This means that when MovableType builds pages that contain PHP code, they must be stored with the .php extensions instead of .htm or .html.

If your index page uses PHP go to the Templates page in MovableType, and click on the index template. Then change the extension of the “Output File” to .php. If the template output file was called “index.htm” you would change it to “index.php”. After you rebuild the index page, you need to delete the old index.htm for the new file to show up.

If your archive pages use PHP go to the Blog Configuration page in MovableType and click on the “Preferences” section. Change the “File extension for archive files” to php (it usually is htm or html). Alternatively, you can use the “Configuration > Archiving” page to specify the extension of your archive files.

Keeping the existing name (PHP in .htm files)
Another approach is to change the server configuration instead of your blog configuration - although not all hosting providers allow you to do this. You can tell the server to treat .htm files withing a directory as PHP files by configuring an .htacces (yes, there is a period at the begining of the file name) file for that directory. If the .htaccess file does not exist in you blog’s directory, you can create a new one in Notepad, otherwise edit the existing one. In either case, to treat all .htm and .html documents in the directory as PHP files, add the following line to the .htacces file:

AddType application/x-httpd-php .htm .html

Server Side Includes (SSI)

SSI is an older scripting language that allows you to create dynamic documents on the server. Documentation for SSI can be found on the NCSA web site.

The following is an example of SSI code embedded in a document. It displays the current date and time:

<!--#config timefmt="%A %B %d, %Y" -->
Current date and time is <!--#echo var="DATE_LOCAL" -->

SSI Server Requirements

SSI documents are executed on the server, and your web server must be configured to support them. Most hosting providers these days have SSI support. The web server recognizes SSI documents by their file extension, which is usually .shtml. This means that when MovableType builds pages that contain SSI, they must be stored with the .shtml extensions instead of .htm or .html.

If your index page uses SSI go to the Templates page in MovableType, and click on the index template. Then change the extension of the “Output File” to .shtml. If the template output file was called “index.htm” you would change it to “index.shtml”. After you rebuild the index page, you need to delete the old index.htm for the new file to show up.

If your archive pages use SSI go to the Blog Configuration page in MovableType and click on the “Preferences” section. Change the “File extension for archive files” to shtml (it usually is htm or html). Alternatively, you can use the “Configuration > Archiving” page to specify the extension of your archive files.

Keeping the existing name (SSI in .htm files)
Another approach is to change the server configuration instead of your blog configuration - although not all hosting providers allow you to do this. You can tell the server to treat .htm files withing a directory as SSI files by configuring an .htacces (yes, there is a period at the begining of the file name) file for that directory. If the .htaccess file does not exist in you blog’s directory, you can create a new one in Notepad, otherwise edit the existing one. In either case, to treat all .htm and .html documents in the directory as SSI files, add the following line to the .htacces file:

AddType text/x-server-parsed-html .htm .html

JavaScript

Since JavaScript is executed inside the browser, there is nothing special that you have to do in MovableType to support it.