Plugin: More Custom Fields Template Tags


Each of the custom field types that More Custom Fields is handled slightly differently. You can use all of the familiar Movable Type template tags to work with any custom field data, but keep reading for some specific notes and tips!

Checkbox Group field type

For an example use of the Checkbox Group field type, lets say you created a custom field named In the Toolbox, which generated the template tag EntryDataIn_the_toolbox.

Simply placing this tag in your template will cause it to produce a comma-separated list of whatever checkboxes were checked:

<p>Tools: <mt:EntryDataIn_the_toolbox></p>

…will output:

<p>Tools: Hammer, Philips head screwdriver, Level</p>

Use MT’s if tag to check if a certain value has been selected. The following would only be printed if “Monkeywrench” were checked in the custom field.

<mt:If tag="EntryDataIn_the_toolbox" like="Monkeywrench">
    <p>Look out! He's got a monkeywrench, and he's not afraid to use it!</p>
</mt:If>

Message

The Message custom field can be output simply using the tag you define for the field. There are no special capabilities.

Multi-Use Single-Line Text Group

As previously noted, this field type is a mouthful. To recap, a breakdown of this field: The Single-Line Text field is included with MT Pro and lets you create a one-line text field. This field type can have many single-line text fields grouped together. Lastly, this is a multi-use field and provides an “add another group” button to add a limitless recurrence of the text fields you’ve defined.

A popular use for this is to display URLs (with “Link Name” and “Link URL” text fields), so let’s use that as an example. I create a new field named “Favorite Links.” Specify the text field names within Options as a comma-separated list: “Link Name,Link URL.” Lastly, my template tag is set to FavoriteLinks.

Outputting the saved contents of this field requires some special handling, and a special block tag is created to help with this. The text “loop” is appended to the specified template tag name to create this special tag. In this example, the special block tag is called FavoriteLinksLoop. So now we’ve got:

<h3>My Favorite Links</h3>
<mt:FavoriteLinksLoop>
</mt:FavoriteLinksLoop>

That doesn’t output our content, however. Within the new Loop block tag, we need to output the variables containing the saved content. To do this you’ll need to use the “dirified” name of your text labels. In our case, the text labels are “Link Name” and “Link URL,” so the dirified names are link_name and link_url. Let’s add these variables (and some HTML) to our template snippet:

<h3>My Favorite Links</h3>
<mt:FavoriteLinksLoop>
<p><a href="<mt:Var name="link_url">"><mt:Var name="link_name"></a></p>
</mt:FavoriteLinksLoop>

I’ve entered several links in the Favorite Links field I created, so it will output the following:

<h3>My Favorite Links</h3>
<p><a href="http://google.com">Google</a></p>
<p><a href="http://danandsherree.com">danandsherree.com</a></p>
<p><a href="http://eatdrinksleepmovabletype.com">Eat Drink Sleep Movable Type</a></p>

Also note that this field uses jQuery. If this field is used for author fields on user profile pages, you’ll want to include jQuery in your Edit Profile template, or rewrite the Javascript for the field to work how you prefer.

Multi-Use Time Stamped Multi-Line Text

A long name, but the idea is simple: this field provides a multi-line text field that is saved with a time stamp. Add additional instances of this field by clicking the “add another…” link. The time stamp will be saved with each instance of the multi-line textarea. This field has no configuration options.

This field can be used in a “breaking news”-type entry, where there may be many updates to the story as it unfolds. Since the textarea is time stamped after each use, the exact time of each story addition can be published, making it easy for readers to see exactly how and when this breaking news is unfolding.

Outputting the contents of this field requires some special handling, and a special block tag is created to help with this. The text “loop” is appended to the specified template tag name to create this special tag. In this example the custom field-created template tag is BreakingNewsUpdates, so the special block tag is BreakingNewsUpdatesLoop.

Within this new tag we can output the variables containing the content added to this field. The variables text and date are used, as in the example below:

<mt:BreakingNewsUpdatesLoop>
<div class="breaking-news-update">
    <p><mt:Var name="text"></p>
    <p>Updated at <mt:Var name="date"></p>
</div>
</mt:BreakingNewsUpdatesLoop>

I’ve entered some simple text in the field, and when published it output the following:

<div class="breaking-news-update">
    <p>This is my first update to this story.</p>
    <p>Updated at July 27, 2011 4:56 PM</p>
</div>
<div class="breaking-news-update">
    <p>Another story update.</p>
    <p>Updated at July 28, 2011 8:12 AM</p>
</div>

This custom field can be sorted in ascending or descending order (according to the timestamp, of course). Use the sort_order key to specify “ascend” or “descend”. Ascend is the default.

The text variable can be optionally formatted with the filters modifier. The date variable can be optionally formatted with the date formats modifiers, though placement of the arguments is unique. In the example below notice the placement of the format argument: inside the Loop block.

<mt:BreakingNewsUpdatesLoop format="%Y-%m-%e" sort_order="descend">
<div class="breaking-news-update">
    <mt:Var name="text" filters="markdown_with_smartypants">
    <p>Updated at <mt:Var name="date"></p>
</div>
</mt:BreakingNewsUpdatesLoop>

Radio Buttons with Input field type

The Radio Buttons with Input field type is much simpler. It works just like the radio buttons field, in fact: any field you create will output the selected option: if Banana is selected, <mt:EntryDataMy_favorite_fruit> will output “Banana.” Similar to the Checkbox Group field type, if you want to check if a certain option is selected use MT’s if tag:

<mt:If tag="EntryDataMy_favorite_fruit" eq="Banana">
    <p>Do you know how to defend yourself against a banana?</p>
</mt:If>

If the last option — the “Other” option — is selected, <mt:EntryDataMy_favorite_fruit> will output “Other: Grapefruit.” That is, the name of the option followed by a colon and a space, and lastly the contents of the text field. If you want to output just the text entry and not the “Other: ” precedent, use MT’s regex_replace modifier:

<mt:EntryDataMy_favorite_fruit regex_replace="Other: (.*)","$1">

Reciprocal Entry Association

The Reciprocal Entry Association field type allows you to link entries together. Output the linked entry with a special block tag, ReciprocalEntry. This tag takes one argument: basename. The basename of your custom field was created when you saved it; in this example it’s my_reciprocal_entry.

<mt:ReciprocalEntry basename="my_reciprocal_entry">
    <p>Read this in Spanish: <a href="<mt:EntryPermalink>"><mt:EntryTitle></a></p>
</mt:ReciprocalEntry>

As the text in the above example implies, the reciprocal entry could be formatted with “read this in English” text to allow the user to go to their preferred language.

Reciprocal Page Association

The Reciprocal Page Association field type works just like the Reciprocal Entry Association field type does, except that it uses a different block tag, ReciprocalPage.

<mt:ReciprocalPage basename="my_reciprocal_page">
    <p>Read this in Spanish: <a href="<mt:PagePermalink>"><mt:PageTitle></a></p>
</mt:ReciprocalPage>

Selected Entries

The Selected Entries field lets you link to other entries. Publishing those entries is a more involved process than working with the other custom field types, but it is still a familiar process. But first, what happens if you just publish the the custom field?

In this series: <mt:EntryDataMultipart_entry>

…will output:

In this series: 119,120,123

…which isn’t very interesting. The numbers you see published here are entry IDs.

More Custom Fields includes a special block tag called SelectedEntries to help you output the kind of result you want! Using the SelectedEntries tag is the key to making this field useful: it makes your selected entries available with the full complement of tags available in the entry context. This tag takes one argument: basename. The basename of your custom field was created when you saved it; in this example it’s multi-part_entry.

<mt:SelectedEntries basename="multi-part_entry">
  <mt:If name="__first__">
    <ul>
  </mt:If>
        <li><a href="<mt:EntryPermalink>"><mt:EntryTitle></a></li>
  <mt:If name="__last__">
    </ul>
  </mt:If>
</mt:SelectedEntries>

Notice that within the SelectedEntries tag you can use the familiar tags found in the entry context, such as EntryTitle and EntryPermalink shown here, but any other tag will work, too.

Selected Pages

Selected Pages works exactly like the Selected Entries field does — except it uses Pages. More Custom Fields includes the block tag SelectedPages to help output your selection, which works just like the SelectedEntries block does. If you’ve created a Selected Pages custom field with the basename of my_favorite_pages you might use the SelectedPages block like this:

<mt:SelectedPages basename="my_favorite_pages">
  <mt:If name="__first__">
    <ul>
  </mt:If>
        <li><a href="<mt:PagePermalink>"><mt:PageTitle></a></li>
  <mt:If name="__last__">
    </ul>
  </mt:If>
</mt:SelectedPages>

Selected Entries or Pages

Selected Entries or Pages works exactly like the Selected Entries field does — except it allows you to select any combination of Entries and Pages for a single instance of this field. More Custom Fields includes the block tag SelectedEntriesOrPages to help output your selection, which works just like the SelectedEntries block does. If you’ve created a Selected Entries or Pages custom field with the basename of featured_content you might use the SelectedPages block like this:

<mt:SelectedEntriesOrPages basename="featured_content">
  <mt:If name="__first__">
    <ul>
  </mt:If>
    <li>
        <mt:if tag="entryclass" eq="page"><img src="pageicon.gif"/><mt:else><img src="entryicon.gif"/></mt:if>
        <a href="<mt:EntryPermalink>"><mt:EntryTitle></a>
    </li>
  <mt:If name="__last__">
    </ul>
  </mt:If>
</mt:SelectedEntriesOrPages>

Note: Because Entries and Pages use the same base object type, entry, many of the Entry tags can be used for Pages.

Selected Assets

Selected Assets also works like Selected Entries and Selected Pages — except it uses assets. More Custom Fields includes the block tag SelectedAssets to help output your selection, which works just like the SelectedEntries block does. If you’ve created a Selected Assets custom field with the basename of my_favorite_assets you might use the SelectedPages block like this:

<mt:SelectedAssets basename="my_favorite_assets">
  <mt:If name="__first__">
    <ul>
  </mt:If>
        <li><a href="<mt:AssetURL>"><mt:AssetLabel></a></li>
  <mt:If name="__last__">
    </ul>
  </mt:If>
</mt:SelectedAssets>