Custom Fields provides the ability for administrators to define additional fields and inputs for a wide variety of objects within Movable Type. This allows Movable Type to become a direct reflection of a user's personal data model and not be restricted to the workflow, data structure and publishing nomenclature most commonly associated with "blogging."
With Custom Fields users can:
- create a "blog" to be a repository for more then just entries - store and manage data for complex e-commerce store fronts, product catalogs, and virtually any data structure you can imagine
- automatically have entry forms adapt to include custom fields without the need to know or edit HTML
- selectively define some custom fields as required fields
- restrict input in a variety of ways for your custom fields using checkboxes, radio buttons, pull-down menus an more
- define the default value a custom field should have
- filter entries and other objects by custom fields values using Movable Type's templating language
The image below shows custom fields in action (the screenshot is actually taken from the Movable Type Plugin Directory which is powered by the Community Solution):
What Objects Can You Extend and How?
Custom fields can be defined for a variety of objects within Movable Type allowing you to customize your data model and work flow for:
- Entries
- Pages
- Categories
- Folders
- Users
Custom fields can also use a variety of different form inputs, including, but not limited to:
- a simple 1-line text field
- a multi-line textarea field
- a pull-down menu
- a set of checkboxes
- a set of radio buttons
- a file uploader
- an asset selector
- a date selector
- a URL
Creating a New Field
Custom Fields are typically defined on a blog-by-blog basis. Meaning, that you can create multiple blogs, each with their own unique and distinct data models.
To begin, select the blog you wish to add the custom field to from the blog selector in the main Movable Type navigation.
Then, from the "Preferences" menu select "Custom Fields." You will then be presented with a table containing all of the custom fields defined within that blog. To create a new field, click the "New Field" link above the table.
You will then be able to fill out a simple form to define your field.
System-wide Custom Fields
Custom fields can also be created at a system level, meaning that if an administrator wishes to add a custom field to every entry for every blog in the entire system, they can do so.
To create a global custom field, follow the instructions for creating a blog-specific custom field, but start from the System Dashboard.
Defining a Pull-down Menu, Radio Buttons and Checkboxes
Some of the fields you may wish to define need to be restricted in some way to a specific set of values. This is required for specific input types like radio buttons, check boxes, and pull-down menus. The mechanism for managing the list of allowed values is the same no matter what type of input is being defined.
To create a pull down menu containing a list of colors for example, create a new field and give it a name of "Favorite Color." In the "Options" field define the list of acceptable values using a comma to delimit each value. For example:
Blue, Green, Yellow, Red, Indigo, Purple, Black, White, Other
Changing the list of allowed values
You can at any time change the list of allowed values associated with a custom field. Doing so will not disturb the current values of existing objects that utilize that field.
Embedding a Field in a Template
As a field is being defined, a basename for the field will be created for you automatically. This basename will serve as the basis for the template tag name used to reference the value contained by that field for the specific entry/page/folder/category in context. A basename is pre-populated for you as a convenience, but can be customized by editing the "Template Tag Name" associated with a custom field.
Movable Type will also present you with a sample template tag that you can cut and paste into a template to display the value of that field for the object in context.
For example, suppose you have a field named "Current Mood" which has a basename of "mood." You can display the mood field for an entry using the following template tag code:
<mt:Entries>
<h2><mt:EntryTitle></h2>
<mt:EntryBody>
<p>My mood: <mt:EntryDataMood></p>
</mt:Entries>
Note: The template tags used to access data stored within a field can easily be customized.
Custom Field Display Options
The display of custom fields within the edit forms for various objects can easily be customized.
First, to toggle the visibility of specific fields within the user interface for Entries for example, select "Display Options" and click the checkbox next to each field you wish to be visible.
Note: making a field invisible will not harm or modify the content it contains.
You may also re-order the display of fields on the page by expanding the "Re-order" widget in the side bar. You can then drag, drop and place the fields in the order you prefer.
4 User Contributed Notes
Can CustomFields still take KeyValue style input in the extended body from external blogging clients? Is there any documentation on this functionality? Thanks.
is there a way to limit field length? In other words... lets say Title - I want a short title - I want authors to be limited in the length of characters for that particular custom field
With the Asset or Image type field, is there a tag attribute I can set so that it only returns the URL of the asset rather than all of the form etc tags?
Here's a challenge:
I have need to access the customfields values in the author record using php. I am on MT-4 with the professional pack.
I have read Arvind's tutorial to access plugindatadata using php (http://blog.movalog.com/a/working-with-php-and-mt-plugindata/) and tried to incorporate it for accessing mt-authors->authormeta->custonfields.
It appears the serialization is a bit more complex but the basic logic should be the same. The blog_id in question is 7.
Here's my code adapted from Arvind's tutorial:
include('/home/theconsulting/www/www/cgi-bin/mt/php/mt.php'); $mt = new MT(7, '/home/theconsulting/www/www/cgi-bin/mt/mt-config.cgi'); $db =& $mt->db; // authormeta where authorid = 'N' // or where authorname = $username $data = $db->getvar("select authormeta from mtauthor where authorname = 'merv.forney@erols.com'", ARRAYA);
// Everything stored in plugindatadata is serialized so to be usable, // we must unserialize it $data = $db->unserialize($data); $geoLat = $data['geocodelatitude']; $geoLong = $data['geocode_longitude'];
There are several custom fields in the author records and I want to get to the GeoCode fields for a Google Map application (both read and write).
It appears the db select is not returning a result. I do not get any php warnings or errors and not sure where to look for MT errors besides the Activity Log (no errors there either). I am absolutely sure the record exists with the author_name supplied in the select statement because it is me.
I'm hoping I have overlooked something simple or perhaps MT-4 has changed significantly since Arvind's example.
Any help you can provide (or point me in the right direction) would be appreciated. Merv Forney