Not a developer? Go to MovableType.com

Documentation

Action Streams Template Author Guide

The Action Streams plugin provides a full suite of template tags for publishing action stream data however you wish.

Examples

See both the examples provided in the plugins/ActionStreams/doc/example_templates directory, as well as the default template set in plugins/ActionStreams/blog_tmpl for a turnkey solution you can disassemble.

The minimal list

The simplest way to list actions is to use the markup provided by the recipe authors with the mt:StreamAction tag. To list the most recent actions by all a blog’s authors, use the template code:

<ul>
    <mt:ActionStreams>
        <li><mt:StreamAction></li>
    </mt:ActionStreams>
</ul>

Action Streams also provides CSS and service icons for showing from what service each action came from. If you include that CSS, use the action-streams and service-icon classes, as in this markup:

<!-- inside the <head> -->
<link rel="stylesheet" type="text/css"
    href="<mt:StaticWebPath>plugins/ActionStreams/css/action-streams.css">
<!-- styles for any extra Action Stream plugins you install -->
<style type="text/css">
    <mt:ProfileServices extra="1"><mt:if name="icon_url">
    .service-<mt:var name="type"> {
        background-image: url(<mt:var name="icon_url">);
    }
    </mt:if></mt:ProfileServices>
</style>

<!-- in your list -->
<div class="action-streams">
    <ul class="action-streams-list">
        <mt:ActionStreams>
        <li class="service-icon service-<mt:var name="service_type">">
            <mt:StreamAction>
        </li>
        </mt:ActionStreams>
    </ul>
</div>

This will show all the icons for the plugin’s known profile services on the published actions.

Custom templates

Sometimes the default <mt:StreamAction> output doesn’t fit, and you want to specify the markup yourself. You might be making a recent photos widget, using <mt:ActionStreams stream="photos"> to list only photos, in which case you’d want to show only the thumbnails from those actions, not the wordy text you get from <mt:StreamAction>.

You can fully specify the markup used for actions using the other template tags supplied by the plugin. In a recent photos widget, you might want to show only linked thumbnails. You would write in your template:

<div class="widget-photos">
    <h3>Recent Photos</h3>

    <ul>
    <mt:ActionStreams stream="photos">
    <li>
        <a href="<mt:StreamActionURL>"
            title="<mt:StreamActionTitle escape="html">">
            <img src="<mt:StreamActionThumbnailURL>"></a>
    </li>
    </mt:ActionStreams>
    </ul>
</div>

See later in this document for documentation on the provided template tags.

Customizing based on type

You may also want to customize only some action templates. For example, you might use Google Reader’s sharing feature to keep a feed of your favorite podcasts. By default, those actions would show up as:

<li>
    Melody shared <a href="...">Favorite Podcast episode #7</a>
    from <a href="...">Favorite Podcast</a>
</li>

Instead, you could conditionally use different template code for those Google Reader actions, using the <mt:If> tag:

<mt:ActionStreams>
    <li>
    <mt:If name="action_type" eq="googlereader_links">

        <mt:AuthorDisplayName escape="html">
        saved <a href="<mt:StreamActionURL escape="html">">
            <mt:StreamActionTitle escape="html">
        </a>
        as a favorite episode of
        <a href="<mt:StreamActionVar name="source_url" escape="html">">
            <mt:StreamActionVar name="source_title" escape="html">
        </a>

    <mt:Else>
        <mt:StreamAction>
    </mt:If>
    </li>
</mt:ActionStreams>

Then all your shared Google Reader items will be customized, but your Digg links and Flickr photos will display as normal. You can customize multiple actions by specifying test attributes on another <mt:Else> tag:

<mt:If name="action_type" eq="googlereader_links">
    <!-- shared on google reader -->
<mt:Else name="action_type" eq="digg_links">
    <!-- dugg on digg -->
<mt:Else>
    <!-- everything else -->
</mt:If>

See the documentation for <mt:ActionStreams> for the variables it sets to help you customize your templates.

Rolling actions up

When there are multiple actions of the same type in a row, the display can be repetitive and boring:

<li>Melody saved <a href="...">some photo</a> as a favorite photo</li>
<li>Melody saved <a href="...">this puppy</a> as a favorite photo</li>
<li>Melody saved <a href="...">a kitten</a>   as a favorite photo</li>
<li>Melody saved <a href="...">omg lol!!</a>  as a favorite photo</li>

By slightly complicating your template code, you can “roll up” these similar actions into one single display item:

<li>
    Melody saved <a href="...">some photo</a>,
    <a href="...">this puppy</a>, <a href="...">a kitten</a>, and
    <a href="...">omg lol!!</a> as favorite photos
</li>

The <mt:StreamActionRollup> tag allows you to peek ahead in the actions loop, producing an inner mini-loop over the next several actions if they are of the same type.

<mt:If name="action_type" eq="flickr_favorites">

    <mt:StreamActionRollup>
        <mt:If name="__first__">
            <mt:AuthorDisplayName escape="html"> saved
        <mt:Else name="__last__">
            and
        <mt:Else>
            ,
        </mt:If>

        <a href="<mt:StreamActionURL escape="html">">
            <mt:StreamActionTitle escape="html">
        </a>

        <mt:If name="__last__">
            as favorite photos
        </mt:If>
    <mt:Else>
        <!-- no sequential Flickr favorites to roll up -->
        <mt:StreamAction>
    </mt:StreamActionRollup>

</mt:Else>
    <!-- not a Flickr favorite -->
    <mt:StreamAction>
</mt:If>

See the template tag reference for full documentation on the <mt:StreamActionRollup> tag and its available arguments.

Selecting authors

Both the <mt:ActionStreams> and <mt:OtherProfiles> tags take several options for picking whose actions or profiles to show.

If one of the below author selecting attributes is used, it specifies the authors. Otherwise, if the tag is used in an author context (such as on an author archive page, inside an <mt:Authors> tag, in an entry context, or on an MT Pro profile page), that one author is selected. Otherwise, if the tag is used in a blog context (most of the time), all the authors who can post to that blog are selected.

The tag attributes for selecting authors are:

author_ids

A list of the numeric IDs of authors to select, separated by commas.

display_names

A list of the full display names of authors to select, separated by commas.

authors

A list of the login usernames of authors to select, separated by commas.

Back

Leave a Comment