Not a developer? Go to MovableType.com

Documentation

Implementing a Settings Template

With your settings template or templates registered, time to actually implement one. Let’s begin by creating a template called blog_config.tmpl and placing it in your plugins tmpl directory.

The first template we will create will expose a single text field with the label “My Setting.” Here is the template code you would use:

<mtapp:setting
  id="my_setting"
  label="My Setting"
  hint="Enter any value you want here."
  show_hint="1">
    <input type="text" name="my_setting" id="my_setting" 
       value="<mt:var name="my_setting">" />
</mtapp:setting>

A couple things to note:

  1. The template above only defines the input elements themselves, the <form> tag that wraps your input element will be generated for you automatically by Movable Type.

  2. Movable Type automatically populates your template with variables that hold the current value of each of your plugin configuration settings. You can use any normal Movable Type template to access these values.

Finally, the single most important detail in making all of this work is utilizing a name for your form elements that are synchronized with the setting you defined for them in your config.yaml. Let’s look at one more example. First your config.yaml:


settings:
  my\_favorite\_color:
    default: "Blue"
    scope: blog

And now the form element that will allow a user to provide a value for this setting:


<mtapp:setting
   id="mysetting"
   label="My Setting"
   hint="Enter any value you want here."
   showhint="1">
<select name="my_favorite_color">
  <option>Red</option>
  <option>Yellow</option>
  <option>Green</option>
  <option>Blue</option>
</select>
</mtapp:setting>

You can include as many form elements that you want. To help you with the styling of these form elements, Movable Type provides the helper <mtapp:setting> tag which makes creating the HTML markup for your forms much, much simpler. Let’s take a closer look at the this template tag so that you can use its fullest benefit.

<mtapp:setting> Properties

  • id - Each application setting tag requires a unique ‘id’ attribute. This id should not be re-used within the template.

  • required - Controls whether the field is displayed with visual cues that the field is a required field or not.

  • label - Supplies the label phrase for the setting.

  • show_label - Controls whether the label portion of the setting is shown or not.

  • shown - Controls whether the setting is visible or not. If specified, adds a “hidden” class to the outermost C

    tag produced for the setting.

  • label_class - Allows an additional CSS class to be applied to the label of the setting.

  • content_class - Allows an addtional CSS class to be applied to the contents of the setting.

  • hint - Supplies a “hint” phrase that provides inline instruction to the user. By default, this hint is hidden, unless the ‘show_hint’ attribute forces it to display.

  • show_hint - Controls whether the inline help ‘hint’ label is shown or not.

  • warning - Supplies a warning message to the user regarding the use of this setting.

  • show_warning - Controls whether the warning message is shown or not.

  • help_page - Identifies a specific page of the MT help documentation for this setting.

  • help_section - Identifies a section name of the MT help documentation for this setting.

Back

Leave a Comment