Movable Type Basics / 2
03/05/2005
I am going to describe the basics of Movable Type in a short introduction. You do not have to know anything about Movable Type for understanding it. However, when following this three-part introduction, you will learn to know the most important components and gain a good overview.
Templates
In the previous part we explained that entries are stored in a database. However, you will not find the website's HTML in the database. Instead, just the attributes of an entry are stored as columns in a database table. But how does Movable Type create HTML out of this?
In Movable Type there are a number of templates. Each of these templates defines how HTML is created from information stored in the database. You will code templates in a special language, whose syntax elements look like XML (although a template is not valid XML).
You will find two different components within a template.
- First, there can be normal HTML. The generator will be copy the HTML to the output unchanged.
- Second, templates can contain special Movable Type tags. They are responsible for accessing the database. Either columns are read (e.g. output the entry's title) or simple flow control is done (e.g. loop over all entries).
If you have some experience with internet application development, then this procedure will probably look very familiar to you. For example, the concept of ASP-pages is very similar.
Let us make two examples so this very important component is better understood.
Example "List of Entries"
Suppose you want to create a list of entries in which only the entries' titles are to be printed. Then you would code as follows.
<ul>
<MTEntries>
<li><$MTEntryTitle$></li>
</MTEntries>
</ul>
You will recognize the normal HTML tags »ul« und »li« for creating a simple list. Additionally there are two Movable Type specific tags. These are »MTEntries« and »MTEntryTitle«.
MTEntries is a so-called container tag. It defines a range and encloses other parts of the source code. If Movable Type finds this tag when rebuilding your website, a loop is started. Anything that is inside the markup will be iterated for each published entry in the database.
MTEntryTitle is a tag that is used for accessing an entry's attribute. Here, the entry's title is output.
Summarizing, the above lines will make Movable Type loop through all published entries and output each entry's title as a list element.
Therefore, the above might cause the following HTML to be generated.
<ul>
<li>Nothing but Problems in the Beginning</li>
<li>Installing under Windows 2003</li>
<li>Umlauts in Filenames</li>
<li>Underscore or Dash?</li>
</ul>
Example "Read More"
Quite certainly, you have seen this on a weblog's start page: some sentences from the beginning of an entry are given. Then there is a "continue reading" link, pointing to the full text of the entry.
Let us have a look at how we might implement this in Movable Type.
<MTEntryBody>
<MTEntryIfExtended>
<p class="extended">
<a href="<$MTEntryPermalink$>">weiter lesen</a>
</p>
</MTEntryIfExtended>
The MTEntryBody is a variable for the text that you entered into the Entry Body textbox. This might be the entire text. Alternatively, if you have also entered some text into the Extended Entry it is only the beginning of the text.
If the Extended Entry field was filled, the condition coded with the MTEntryIfExtended tag becomes true. Only if the condition is true, the embedded lines are copied to the output.
Within the link, a Movable Type tag is used as the URL. The MTEntryPermalink is the URL that points to the entry.
If you entered the full text into the Entry Body, Movable Type might create the following output.
<p>This is the entry's full text.</p>
However, if you distributed the text on the Entry Body and the Extended Entry, Movable Type might create the following output.
<p>This is the entry's first part.</p>
<p class="extended">
<a href="http://www.movable-type.de/demo.html</a>
</p>
Template Types
A standard installation of Movable Type will result in about 20 templates. These are grouped as follows.
- The Index Templates are responsible for the layout of the index pages that we mentioned in the previous chapter. Usually a list of the most recently published entries is given. A weblog might also have other index templates. For example, in my Movable Type Weblog there is the start page with the 10 most recently published entries, a simple list of all entries and a grouped list showing entries according to their category. The last two lists are accessible via the sitemap.
- The Archive Templates are responsible for the layout of the archive pages, also mentioned in the previous chapter. For example, these pages will collect all entries for a month or for a category.
- The Special Templates define the layout of certain special pages. For example, the layout of a comment listing or comment preview is defined here.
- The Template Modules allow creating own templates that are to be used in other templates. If you realize that two templates contain identical functions, you should think about creating a template module and referencing it from other templates.
To Be Continued
This introduction consists of the following three parts
You have just read part 2.
mgs | 03/05/2005
Feedback is welcome!
What do you think about this entry? Was it interesting or boring? I would like to hear your comments. If the text was helpful, please consider setting a link to http://www.movable-type-weblog.com/.
No spam please!
For protecting this weblog I have installed the MT-Approval Plugin. You have to view a new comment in preview mode, before it is saved on the server. Moreover, I will view your comment manually, before it is published. You can find more information on the subject in the entry Weblog Spamming Basics.
With an active TypeKey session, your comment will be published immediately.
Post a new comment
TypeKey has temporarily been disabled at this location. Please create your comment without using TypeKey or log in from the preview dialog.

