MTExtendedAttribute

Current version is 1.1.0 (6 Feb 2003)

This plugin gives you a new Movable Type template tag: <$MTExtendedAttribute$>. This tag allows you to associate additional fields and values with Movable Type Blogs, Categories, Entries, and Authors. These additional fields and values can be stored either in a data file in your file system, or in a Template Module. The format of the stored data is standard CSV (Comma Separated Values), so you can edit it by hand, or use a spreadsheet program like Excel or OpenOffice Calc.

For example:

  • You could define a "long" blog description and a "short" blog description, so you can show the long description on your index page, and have the short description on your archive pages.
  • You could define multiple icons or pictures for each category. So you could have a small category icon beside each entry on your index page, and a larger version of it on the category index page.
  • You could flag certain entries in your blog as extra special, by defining a stylesheet that only gets attached to the archive pages for these entries.
  • You could define additional style attributes on a per-author basis, so that posts by different authors show up in different colours or fonts.

...And much more.

Most (if not all) of the examples I've noted above can also be achieved with other techniques. Brad Choate's MTMacros and Key Values plugins can take care of a great deal Also, by giving images and stylesheets names that match your categories and authors, you can achieve extensive visual customizations. The <$MTExtendedAttribute$> tag makes doing all this just a little bit easier, though.

Important note:

Like the <MTCalendar> tag, the <MTExtendedAttribute> tag is computationally quite expensive. If you define large amounts of extra data, it can add significantly to the time it takes to rebuild your pages. In small doses, though, it is hardly noticeable. But if you're just looking for a way to attach icons to your categories, you may be better off using A42's <MTTopicIcon> tag.

In real life:

To see a (simple) real-life illustration of the tag in action, visit my blog at http://www.sunpig.com/martin/. In the sidebar on the right hand side of the page, I have got a section for "quick reviews". This is a sub-blog, with the following categories defined:

  • Books - 5 stars
  • Books - 4.5 stars
  • ...
  • Books - 0.5 stars
  • Books - 0 stars
  • Films - 5 stars
  • ...
  • Films - 0 stars
  • Food - 5 stars
  • ...
  • Food - 0 stars

Within this blog, I have a template module called "CategoryAttributes", which contains CSV data. (You can see the data here.) I use this to show two images alongside each entry: an icon to show whether the entry is a book, film, or a food review, and an icon to show how many stars I've given it. I also use the CSV data to define alt and title text for the images.

  1. Download the latest version of the plugin
  2. Unzip the contents of the file
  3. Copy the file ExtendedAttribute.pl to your Movable Type "plugins" directory. (If you don't already have a plugins directory, create it in the same directory where your mt.cgi file is located, and then upload ExtendedAttribute.pl)
  4. Change the permissions on ExtendedAttribute.pl to 755

Your extended attributes must be stored in CSV format. If you have a spreadsheet program like Excel or OpenOffice Calc, this is easy and quick. If not, you can just use a text editor.

The first thing you need to know is the IDs of the things you're giving extra attributes to: these are the Blog IDs, the Category IDs, the Entry IDs and the Author IDs. These IDs are how your extra attributes are linked to the various items. You can find them as follows:

Blog ID

When you're in any of the editing screens for a particular blog, the blog id is given in the URL for the page:
http://localhost/mt/mt.cgi?__mode=list_cat&blog_id=1
The blog id for this blog is 1.

Category ID

Go to the category editing screen for a particular blog. All of the blog's categories are listed here. If you hover your mouse over the link that says "Edit category attributes" next to a category, in your browser's status bar you'll see the URL for editing that category, which contains the category id:
http://localhost/mt/mt.cgi?__mode=view&_type=category&blog_id=1&id=35
The ID for this category is 35

Entry ID

Go to the editing screen for a particular entry. The entry id is given in the URL for the page:
http://localhost/mt/mt.cgi?__mode=view&_type=entry&id=209&blog_id=1
The ID for this entry is 209

Author ID

Go to the add/edit authors screen for your blog, and list all authors. When you hover over each author's name, in your browser's status bar you'll see the URL for editing that author, which contains the author id:
http://frankenstein/mt/mt.cgi?__mode=edit_permissions&author_id=2
The ID for this author is 2

Once you have found the IDs of the things you want to assign extra attributes to, you have to decide what the extra attributes will be. For a category, some examples might be "Description 1", "Description 2", "Description 3", "Small Icon", "Big Icon".

The CSV data format is basically a plain text definition of a spreadsheet grid, where each row is a new line in the text, and columns are separated by commas. If you have a data field that itself contains a comma, you must enclose the whole field in quotation marks (""). If the field contains quotation marks, you must also enclose the field in quotation marks, and then turn each quotatition mark within the field (") into double quotation marks ("").

If you have a spreadsheet program, this is a lot simpler: all you have to do is put the extra attributes into the spreadsheet and then "Save As" a file of type "CSV". You can then copy this CSV file to your web server, or you can open it up in a text editor and copy the text out of it into a template module in your Blog.

For illustrative purposes, I'm going to assume that you're using a spreadsheet program to edit the attribute data.

Okay, so you have your list of category IDs, and you want to give each of these categories some extra descriptions, and associate icons with them. Open your spreadsheet, and put the names of these new attributes in the first row of the spreadsheet. Note that the very first attribute, and the first cell in the row, must be "ID", because the IDs of the categories will go in the first column.

The header row

Next, fill enter your IDs in the first column.

IDs in the first column

Finally, fill in your data!

The rest of the data

Save the data as a CSV file.

Save as CSV

You can see the finished version here

You can take this csv file and copy it to the web server where your blog resides, or you can copy the text out of the file and put it in a new template module--whichever you prefer. The <$MTExtendedAttribute$> tag is capable of reading from both files and templates.

Next, you have to tell the tag how to interpret the data.

The tag has six parameters: file, module, type, name, index, and headerrow. The last two parameters are "advanced" parameters--you don't need them to get started with using the tag.

file (you must have either a file or a module parameter)

This tells the tag what file the extended attribute data is stored in. Note that this is the full file path to the file--it isn't relative to your blog directory. On unix systems, it will look something like "/home/username/www/categoryattributes.csv". On Windows systems, it will look something like "E:\inetpub\wwwroot\username\categoryattributes.csv"

module (you must have either a file or a module parameter)

This tells the tag what template module the extended attribute data is stored in. This is just the name of a template module in your movable type system. Note that because Movable Type treats modules in a case-sensitive manner, you must enter the module name in the same case as it is defined in your blog.

(Also note that if you specify both a file and a module, only the module will be used.)

type (mandatory)

This tells the tag what context it is being used in. The four options here are "blog", "category", "entry", and "author". The parameters are not case-sensitive. For example, if you use the <$MTExtendedAttribute$> tag in the context of an entry, and set the type to "category", the tag will try to match the ID of the entry's category against a line in your CSV data file.

name (mandatory, unless you specify an index parameter)

This tells the tag the name of the extended attribute it should look up. In the example data file, this could be "Small Icon", "Big Icon", "Description 1", "Description 2", or "Description 3". (These names/column headers are not case-sensitive.)

index (mandatory, unless you specify a name parameter)

This tells the tag the "index" of the extended attribute it should look up: this is the number of the column the data item can be found in. Note that the first column (the one with the ID in it) is index 0. The first column with actual attribute data is index 1, the second column with attribute data is index 2, etc.

Using an index rather than a name is slightly faster, because the tag doesn't have to decode the names in the header row and match the names against the "name" parameter. However, it does make it more difficult if you want to insert more columns into your data file at a later stage.

headerrow (optional)

This parameter tells the tag whether the first row in your data file is a header row with the names of your extended attribute. If you don't specify this parameter, the tag assumes that there is a header row present. If you're using the "index" parameter, and so don't need to specify names in the column headers, you may set headerrow="0" to let the tag know that no header row is available. (If you don't, it will assume that the first row contains headers, and will skip it.)

Examples:

With extended blog attributes defined in the "BlogAttributes" template module, show the "ShortBlogDescription" data for a blog:
<$MTExtendedAttribute module="BlogAttributes" type="blog" name="ShortBlogDescription" $>
Same, but with the attributes defined a file:
<$MTExtendedAttribute file="/home/martin/blog/blogattributes.csv" type="blog" name="ShortBlogDescription" $>
Use indexing instead of named attributes:
<$MTExtendedAttribute file="/home/martin/blog/blogattributes.csv" type="blog" index="4" headerrow="0" $>
Show a category icon next to an entry's title, and an icon next to the entry's author:
<MTEntries>
  <h2>
    <img src="<$MTExtendedAttribute module="CategoryAttributes" type="category" name="TitleIcon" $>" alt="<$MTExtendedAttribute module="CategoryAttributes" type="category" name="TitleIconAltText" $>" />
    <$MTEntryTitle$>
  </h2>
  <p><$MTEntryBody$></p>
  <p>
    <$MTEntryAuthor$>
    <img src="<$MTExtendedAttribute module="AuthorAttributes" type="author" name="Small Icon" $>" alt="<$MTExtendedAttribute module="AuthorAttributes" type="author" name="Author Icon Alt" $>" />
  </p>
</MTEntries>
Real-life example: my "quick reviews" sidebar. See the CSV data here
<div class="sidebarsection">
  <div class="sidebarcaption">Quick reviews</div>
  <div class="sidebarcontent">
    <MTEntries lastn="5">
    <div class="readinglisttitle"><$MTExtendedAttribute type="category" name="TypeIcon" module="CategoryAttributes" $><span><$MTEntryTitle$></span></div>
    <div class="readinglistbody"><$MTEntryBody$><$MTExtendedAttribute type="category" name="Stars" module="CategoryAttributes" $></div><hr />
    </MTEntries>
<br /><a href="<$MTBlogURL$>" class="sidebarlink" title="Show more">More quick reviews...</a>
  </div>
</div>

1.1.0 - 6 Feb 2003

New feature: Thanks to a suggestion from John Howard, the MTExtendedAttribute tag can now pick up an Author ID from within the context of Brad Choate's <MTAuthors> plugin. If you have a page that uses the MTAuthors to show all the authors associated with your blog, you can now use MTExtendedAttribute to display additional data about these authors, such as IM names, addresses, favourite pizza toppings, or anything else that can be fitted into CSV data.

1.0.1 - 3 Dec 2002

Bug fix: I had left a line of debugging code in the section of the plugin that deals with getting the column headers, when you're using a file for storing your CSV data. This was causing the plugin not to be able to figure out what field you wanted from the data file, and thus not display anything at all. (This bug does not affect CSV data in template modules.)

1.0 - 28 November 2002

First public release

  • In fixing the bug for version 1.0.1, I found that the plugin doesn't display error/warning messages correctly on my Linux system. My main development platform is Windows XP, and the error messages appear fine there, but there seems to be some difference in the way that my Linux system treats (some?) error conditions. (Different version of Perl?) Further investigation required.

For questions, suggestions, bug reports, and anything else related to this plugin, please email MTExtendedAttribute@sunpig.com, or contact me on the Movable Type Support Forum