It starts with the “header” area. On my site that area’s the same throughout, so there’s no reason to not have it in one generalized place. We’ll then include that in all of our templates which need it, and then when we edit it in one place the whole site will reflect the change.
Clicking on the “Templates” link in the left hand column brings you to the “List Templates” page. The first section is titled “Index Templates” which are a special breed of templates which get ‘rendered’ off to disk with the option of rendering them every time you rebuild your site.
Note: Notce I used the word ‘render’ there. It’s a throw back to Userland Frontier and it means “saved off to disk after completing all the needed variable substitution”. THat means if your template has MT Tags in it, they will be replaced with their HTML meaning in the final file.
OK, so click on the Template named “Main Index” to enter its editing window. in the text entry field labeled “Template Body”, scroll down a bit until you see an
Copy that whole DIV to your clipboard. Be careful not to screw up any DIV nesting…
Click the “List Templates” section of the Breadcumb nav, or “Templates” in the left side nav.
Scroll down the page to the oft neglected section called “Template Modules”. It’ll look like:
Click the “Create new template module” link and paste the div you just copied into the text edit field labeled “Module Body”. Name the Template something memorable like “banner” in the “Template Name” filed at the top and click the “SAVE” button. What this does, is it saves that fragment of HTML into the database so the MovableType engine can get to it any time it needs it.
Go back to the “List Templates” page (iehter by the breadcrumb route or the side nav) and scroll down the “Template Body” section again to the “banner” DIV. Select and delete that and type in an MT TemplateTag called the include tag. Type in this:
<$MTInclude module="header"$>
That tells MovableType that next time it renders the page (or any page derived from that template) to pull that text from the database and replace that tag with the text. Save and rebuild that page and, guess what? It looks just like it did before.
Why’d we do that?
To save time, so you can do things besides re-editing the same markup in multiple places. Ultimately the idea is to minimalize the boring, repetitive work so you can get away from your desk sooner, get home to your family and have more sex. That’s it, smart work habits will make you work faster and get you laid more often. That’s got to be a motivating factor for most of us.
Also, on an object oriented note, because templates shouldn’t really have much markup in them they should hold the structure of hte page and variables which get replaced at render-time (as opposed to run-time, which is when the site visitor views the page).
To really leverage this benefit, paste that MTinclude tag into any template you want that top Banner to appear in. Probably your Master Archive Index, your Category Archive, Date-Based Archive and your Individual Archive. now, if you change the Template Module named “banner” the change will roll out to your whole site next time you rebuild.
Bare in mind, that you can combine multiple Include tags in other Templates to increase the value even further. We’ll do that in our next exercise “Extending the Banner”