Movable Type Documentation > Developer > Plugins

Registering Dashboard Widgets

Movable Type's Dashboard is designed to give administrators and users of Movable Type an overview of activity happening within the system or on a single blog. Movable Type ships with a number of dashboard widgets by default, including:

  • This is You - a mini-stats about your authoring stats
  • Comment Stats - a graphical widget that shows commenting activity
  • Entry Stats - a graphical widget that shows authoring activity
  • Tag Cloud - a list of frequently used tags
  • MT News - a summary of the latest Movable Type news
  • Shortcuts - a list of handy links users commonly access

Movable Type allows developers to define their own Dashboard Widgets using Movable Type's templating language. These widgets can then be registered with the system to allow users to add them to their dashboard with a click of a button.

To register a widget add the following code to your plugin:

sub init_registry {
    my $plugin = shift;
    $plugin->registry({
        widgets => {
            hello_world => {
                label    => 'Hello World',
                plugin   => $plugin,
                template => 'hello_world.mtml',
            },
        },
    });
}

Then in tmpl/hello_world.mtml you place the following code:

<mtapp:widget class="widget hw-widget"
    label="<__trans phrase="Hello World">"
    can_close="1">
    <h1>HELLO WORLD</h1>
</mtapp:widget>

dashboard-widget.png

You can also specify a few other fields:

Dashboard Widget Registry Properties

When registering a widget the following properties can be used.

system_permission and permission

Requires a certain permission or system-wide permission (on the system dashboard) to add and use the widget. For example, permission => 'post' would require the user to be able to post to the blog to add your widget to that dashboard. Specify more than one permission using commas.

condition

Requires a custom handler to approve of the user and dashboard to add and use the widget. Your coderef is passed ($page, $scope) where $page is "dashboard" and $scope is either "dashboard:system" or "dashboard:blog:blog_id".

singular

Allows only one instance of the widget on a dashboard, if set true. The widget won't show up in the "Add widget" list if it's already been selected.

set

Specifies only a certain column of the dashboard can contain the widget. Set it to main or sidebar to only allow the widget in one or the other.

code or handler

Customizes the widget's runtime environment however you like. The callback/handler you specify here will be called with parameters ($app, $tmpl, $widget_param) where $tmpl is the template you specified with template and $widget_param is the parameter set against which your template will be built. When your callback is called it will already contain:

  • The keys and values from the dashboard page so far
  • The param value from your widget config (I don't fully grok widget config)
  • blog_id if any
  • widget_block, the part of the dashboard your widget is in (main or sidebar)
  • widget_id, the key you filed your widget under in the registry
  • widget_scope, the scope of the dashboard your widget is in (see condition above)
  • widget_singular, what you set in your singular option
  • magic_token, your CSRF-proof token for submitting forms

Note that if through your template or code callback you set the html_head or js_include variables, those values will be appended to the dashboard page's variables of the same name. You can inject stylesheets and behavior that way. No other content is allowed to escape your widget processing.

This page was last updated on 2007-08-28, 09:37.  

Submit a User Contributed Note

User contributed notes are a great way to share the knowledge you have gained in using Movable Type.

If you have a technical question or problem, please visit Movable Type Support.

(If you haven't left a note here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)