Using include(); for an easy template management in Movable Type

in Movable Type

When dealing with Movable Type, you will find many templates to modify. You will have Main Index template, Individual Archive Template, Category Archive Template, Date-based Archive Template and many more. But, do you realize that those template has some similarities on some parts?

For example, usually you will have the a same footer area. Your header navigation, and meta tags will be similar, or exactly the same. If you only want to make changes on the footer on every pages, do you have to modify each template? Yes, you should. But, let’s save your time by using PHP include(); function.

Notes

Because we will use PHP code here, you need to treat your file as a PHP file, so that the code will be read correctly. If you publish your file using .html extension and you put PHP code there, your PHP code will not be processed. You will have the code displayed as it is written. The easiest solution for this is to change the extension to .php. Go to “Settings” » “Publishing” and change the file extension there.

Using .htaccess you can also treat .html files as PHP files. You can do it from your webhosting control panel. Most control panel can do this. Go to Mime Types editor, or Mime Types management there.

Or, if you can add this line to your .htaccess (if this file does not exist, you need to create it): AddType application/x-httpd-php .html

Example: Inserting footer file anywhere!

Okey, this is an example:

You have a same footer text, and you want to put it in every template. You also want to be able to change the footer, without modifying all template, and rebuilding the site.

First, you need to put the your footer area, for example, you can make a file called footer.php. Save this file somewhere in your website e.g. under /home/username/public_html/template/footer.php. Your footer.php will have this line:

<div class="footer">&copy; mywebsite.com</div>

Now, in your Main Index template, in the footer, you need to replace <div class=”">&copy; mywebsite.com</div> with this PHP code:

<?php include("/home/username/public_html/template/footer.php"); ?>

You can do the same with your other template. Save, and rebuild. From now on, if you want to make changes on the footer, you need to edit footer.php.

If you're new here, you may want to subscribe to my RSS feed go get the latest entry from your RSS reader. You can also have my contents delivered to your inbox.