Enabling Tags in an Entry
03/30/2005
Movable Type knows templates and entries. The templates define the structure of the HTML pages. Inside the entries there is the content for those pages. Unfortunately the tags, which are used in the templates, are forbidden inside entries. But there is a way out.
In Entries there is Text. Why do you need Tags?
Entries mainly consist of text. But there are situations where you wished that tags were allowed. Using tags for control flow is probably not the primary wish. But using tags as variables is very reasonable.
Let us make a simple example. Most weblogs also contain images. These are usually saved into a directory »images« under the root folder. But how do you address these images from within your entries? Of course it is possible to address them with an absolute URL.
<img src="http://www.movable-type-weblog.com/images/a.jpg" />
This does work, but it has a clear disadvantage. For example, if you change your domain all such references will be invalid. This will also happen if you maintain separate test and production environments. The usual solution is addressing the images not with an absolute but with a relative URL. In this case the domain name would be removed from the URL and the address would start with the »images« directory.
<img src="images/demo.jpg" />
However, this only works if the HTML page containing the img tag is located above the »images« directory. But if you have archive directories, the resulting HTML will be at varying locations. In one case the reference might be valid, in another case it might be invalid.
The problem could be solved easily, if Movable Type also "executed" the content of an entry, thus allowing tags inside entries. For example there is a »MTBlogURL« tag which contains the root address. It could be used for building a reference to an image file without any need for an absolute URL. So we want Movable Type to support something like the following.
<img src="<MTBlogURL>images/a.jpg" />
Unfortunately Movable Type will not interpret any tags inside an entry. The content of an entry is copied unmodified into the resulting output. Movable Type does not analyze the text and does not execute any tags contained inside.
Fortunately there is a plugin for almost anything you can imagine.
Process Tags Plugin
There is a plugin that is able to make Movable Type evaluate an entry's text. It is the so-called Process Tags Plugin.
Installing the plugin is very simple. After having downloaded the plugin from the above location, you have to copy the files »processtags.pl« and »postproc.pm« into directories below your Movable Type installation. If necessary these directories have to be created in advance.
<MT>/plugins/processtags.pl
<MT>/extlib/bradchoate/postproc.pm
This simple copying is enough for making the functions inside the two files known to Movable Type. Now we only have to ensure that these functions are called. For this, we have to modify the templates slightly: the tags whose content is to be executed must be extended with an additional attribute.
Your template for the individual archive will most likely use the two tags »MTEntryBody« und »MTEntryMore«. Extend these tags as follows.
<MTEntryBody process_tags="1">
<MTEntryMore process_tags="1">
The additional attribute »process_tags« specifies that a function has to be called, which in turn takes care of the content being interpreted.
I have not done any measurements. But I suspect that rebuilding the site is slowed down due to this plugin. You should watch the process carefully.
mgs | 03/30/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.

