Adding a Simple Template Tag
Now that you have created your first Movable Type configuration directive, we need a way to display it’s assigned value on a blog or web site. Hopefully you will find accomplishing this just as simple as before, however, this time we will need to actually create some code.
A Word About Perl
Perl has a reputation for being impossible to read and overly complex. There is a kernel of truth to every stereotype I suppose, but the truth is that Perl need not be complex or scary to the average programmer. In fact, pretty code versus ugly code is more of a reflection of the programmer who wrote it, then it is of the language itself. But be that as it may, the following examples should show that virtually any person who is familiar with PHP or Javascript has the knowledge they need to write enough Perl code to be dangerous; and furthermore they can write readable Perl in the process.
As always, let’s start with the YAML you will need to define your first template tag:
name: Good for Nothing Plugin for Movable Type
id: Good4Nothing
author_link: http://www.yourwebsite.com/
author_name: Your Name Here
description: This plugin is an example plugin for Movable Type.
version: 1.0
config_settings:
MyImageURL:
default: http://www.movabletype.com/images/overview-1.jpg
tags:
function:
MyImageURL: $Good4Nothing::Good4Nothing::Plugin::tag
There are a couple of things going on here. First the ‘function’ key defines the type of tag we are creating (we will review the other types of tags later in this manual). A function
template tag simply outputs text.
The child element of function
is MyImageURL
, which defines the name of your template tag. The value of MyImageURL
is a reference to a subroutine defined elsewhere in your plugin. When you include this template tag on your web site, Movable Type will invoke the subroutine called “tag” located in the module “Good4Nothing::Plugin” defined by the plugin called “$Good4Nothing” (corresponding to the ‘key’ used when registering your plugin).
Finally, Movable Type will support multiple case-insensitive syntaxes in referencing the tag name you create. For example, all of the follow are valid ways to refer to the template tag defined above:
<mt:MyImageURL>
<mt:myimageurl>
<$MTMyImageURL$>
<$mt:myimageurl$>
<mtmyimageurl>
Ok, take a deep breath, it is time for some code.