Oct 8

Adding User-Defined Fields in Movable Type

I’ve complained off and on about the lack of user-defined fields in Movable Type. Today was finally the day I got off my high-horse and messed with some code.

Here is a method to add a new field to the MT database. The field can store whatever you like, can be queryed on and sorted by (via Brad Choate’s marvelous SQL plugin), and has its own template tag.


Comments

by john,   October 8, 2003 8:29 AM  

Outstanding Deane - Next time I need this functionality I'll give it a try.


by Deane,   October 8, 2003 12:22 PM  

For my next trick, I want MT to use different "edit_entry" templates for each blog, so that you can customize the editing interface -- label the fields differently, have different form elements, etc.

For instance, you could have a blog for an event calendar, and have fields for "recorrance," "start time," "end time," etc. Instead of the user having to remember want info gets hacked into what field, you could present them with a customized editor.


by Mean Dean,   November 12, 2003 3:51 PM  

Why didn't I see this post earlier? I could kiss you on the lips for this one.

I've been thinking, if I could just add 2 fields, I could take the "web links" portion of blogs4God and move it entirely into MovableType.


by Mean Dean,   November 13, 2003 6:29 AM  

It's official, you've been blogged: http://www.healyourchurchwebsite.com/archives/001073.shtml


by Deane,   January 5, 2004 11:07 PM  

I just did an install with no less than six user-defined fields: one for key/value information, and five for whatever. It seems to work perfectly.


by Hans,   July 29, 2004 1:44 PM  

Thanks for the great hack! It is very well described and even feaseable for a "faint of heart" as me.

An addition: If you want to use the public search module built in MovableType (I use 2.661) you just need to extend a single line in

/lib/MT/App/Search.pm

Around line 440 you'll find the subroutine sub searchhit

Just add your new field like this:

@textelements = ($entry->title, $entry->text, $entry->textmore, $entry->keywords, $entry->user1);

and you are done.


by zeebeest,   October 17, 2004 1:56 PM  

Hi,

this hack doesn't seem to work with version 3.11. Was anyone of you able to do the same thing in v3.11?


by sasco,   October 31, 2004 12:12 PM  

The main problem I'm having in MT v.3.* is that the template file no longer uses tables, instead it uses CSS for everything. I'm sure this is still a feasable hack but it's going to take someone a lot smarter than me to figure it out.


by zeebeest,   November 2, 2004 10:09 AM  

Ah I figured it out!

I added a post on how to add an extra field (including changing some other back-end display options and taking into account your new field in the export function) on my site (see Category MovableType) in Dutch. I'm planning on translating the post to English as well, but in the mean time:

If anyone needs any help on this in any other language then just let me know (not here, but on my own site...)!


by Fabio,   December 8, 2004 10:37 AM  

Hi :) just used that and some other stuff i developed to build some avatar stuff on my site's comments system :))

thanks! if you want to know what i did contact me on morroida at gmail :)


by mattiz,   March 7, 2005 10:34 AM  

You are a hero! This works excellent and very easy to do.


by PeteoFun,   April 27, 2005 6:00 PM  

This hack is great, and makes MT more of an all purpose CMS. I wish it didn't prevent upgrading MT's version though.


by Craig,   June 6, 2005 9:38 AM  

Thanks for these instructions. I implemented them with 2.66 but soon enough it got to be a pain to upload my saved tmpl files all the time.

I think I will settle for Brad Choate's KeyValue plugin, even if it is a little less 'elegant' because I don't need to "upgrade" every upgrade. This is a personal choice but for people who would rather not bother tweaking code everytime, it is worthy of consideration.


by Ben,   July 21, 2005 8:10 AM  

Hi, Thanks for the tip. Unfortunately, I am looking for native support of this feature since I am running under the BerkleyDB, not MySql. But, thanks again for sharing this with me. I'll bookmark it and maybe I will switch to MySql in the near future so this will work.


by Dave,   August 31, 2005 5:01 PM  

Hey thanks for this - got the bank end working fine - but when i try to build the site, i get

Undefined subroutine &MT::Template::Context::hdlrentry_location called at lib/MT/Builder.pm line 159. any ideas?

line 59 is : my $out = $h->($ctx, \%args, $cond);

thanks!


by Dave,   August 31, 2005 5:41 PM  

Found the problem! Is was the space between sub and hdlrentry_user1 {

sub hdlrentry_user1 {

should be

subhdlrentry_user1 {

thanks!


by Dave,   August 31, 2005 7:01 PM  

Ok, I'm stuck now!

It's all working in the backend

I've got nice fat tags in my individual template like

But nothing appears!

Any ideas?


by Dave,   September 1, 2005 4:09 AM  

fixed it - stoopid typo in context.pm - sorry!


by Kevin,   January 23, 2006 1:02 PM  

Hi, thanks for the tip! I have a question I'm hoping someone can answer. I added a new field that holds an integer, and everything worked great. So I tried adding a second field the exact same way as the first (only difference is that it holds a varchar(40) data type in the mysql db). However, whenever I reference my other tag, I get the following error:

"Building results failed: Error in tag: Error in tag: You used an 'MTEntryBoxShot' tag outside of the context of an entry; perhaps you mistakenly placed it outside of an 'MTEntries' container?"

Again, I followed the instructions exactly the same in both cases, but for some reason, the second on I added wants to be inside an tag. Any ideas?


by Kevin,   January 23, 2006 4:16 PM  

Nevermind, I figured out my problem :)

Thanks again for such a well written tutorial, this was a life-saver for me on a project I'm working on right now.


  • There are 23 comments on this entry.
  • 20 comments have been displayed above.
Load the next 20 comments.

Add Comment


Want to advertise on this site? Contact FM.
Web Hosting Web hosting, dedicated servers and Web design services
Laser Toner Cartridges UK laser toner, toner cartridges, hp toner, lexmark toner, samsung toner, canon, toner, epson toner, oki toner, kyocera toner, xerox toner, remanufactured toner, compatible toner
Direct TV Deals Free 4 room direct tv deals. no equipment to buy. free fast professional direct tv installation. this is the best direct tv deal available anywhere.
SEO Article Learn from the experts with our SEO article.
rope light Shopping with birddog distributing, inc., gives you access to the lowest prices, the best customer service and the quickest delivery times possible.
Laptop AC Adapter We offer genuine factory direct replacement AC adapters.
Direct TV Best satellite TV deals.
Direct TV Deals Direct TV programming deals are varied and include packages containing from 50 channels up to over 250 channels.
8mm film to DVD Retain family memories with the only frame by frame digital restoration service in the United States for your 8mm film to DVD today
Rubber Stamp Shop for custom self-inking stamps, hand stamps, address stamps, label stamps, check endorsement stamps, check deposit stamps, date stamps, pre inks, pocket stamps, ink and much more!