Plugin: More Custom Fields Template Tags
- Overview
- Install and Configure
- Template Tags
- Changelog & Known Issues
- Looking for support? Use the Helpdesk
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>
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">
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>