December 2009 Archives

Using MTML, you can sort assets by label in an entry context like this:

<mt:EntryAssets sort_by="label">
    <!-- asset content here -->
</mt:EntryAssets>

However on the Edit Entry screen the filename for each asset is listed, but the assets are not sorted by filename.

The following steps will update the Edit Entry/Page screen to list assets by asset label…

Three App Templates to Edit

$MT_HOME/tmpl/cms/edit_entry.tmpl

Update the template that produces the Edit Entry/Page screen.

  1. Line 491:

    <mt:var name="asset_name">
    

    Change to:

    <mt:var name="asset_label"> [<mt:var name="asset_name">]
    

$MT_HOME/lib/MT/CMS/Entry.pm

Update the script that collects the assets in the sidebar of the Edit Entry/Page screen.

  1. Line 191:

    $asset_1 = {asset_id => $asset->id, asset_name => $asset->file_name, asset_thumb => $asset->thumbnail_url(Width=>100)};
    

    Change to:

    $asset_1 = {asset_id => $asset->id, asset_name => $asset->file_name, asset_label => $asset->label, asset_thumb => $asset->thumbnail_url(Width=>100)};
    
  2. Line 193:

    $asset_1 = {asset_id => $asset->id, asset_name => $asset->file_name};
    

    Change to:

    $asset_1 = {asset_id => $asset->id, asset_name => $asset->file_name, asset_label => $asset->label};
    
  3. Line 201:

    my $asset_1 = {asset_id => $asset->id, asset_name => $asset->file_name};
    

    Change to:

    my $asset_1 = {asset_id => $asset->id, asset_name => $asset->file_name, asset_label => $asset->label};
    
  4. Line 210:

    $asset_1 = {asset_id => $asset->id, asset_name => $asset->file_name, asset_thumb => $asset->thumbnail_url(Width=>100)};
    

    Change to:

    $asset_1 = {asset_id => $asset->id, asset_name => $asset->file_name, asset_label => $asset->label, asset_thumb => $asset->thumbnail_url(Width=>100)};
    
  5. Line 212:

    $asset_1 = {asset_id => $asset->id, asset_name => $asset->file_name};
    

    Change to:

    $asset_1 = {asset_id => $asset->id, asset_name => $asset->file_name, asset_label => $asset->label};
    
  6. Line 217: This will sort assets by asset_label:

    $param->{asset_loop} = $assets;
    

    Change to:

    $param->{asset_loop} = [ map $_->[1], sort { $a->[0] cmp $b->[0] } map { [ $_->{asset_label}, $_ ] } @$assets ];
    

$MT_HOME/tmpl/cms/dialog/asset_insert.tmpl

Update the script that inserts the asset into the list of assets once selected.

  1. Line43

    myAssetLink.appendChild(document.createTextNode('<mt:AssetLabel encode_js="1"> [<mt:AssetFileName encode_js="1">]'));
    

    Change to:

    myAssetLink.appendChild(document.createTextNode('<mt:AssetFileName encode_js="1">'));
    

Without using a plugin, the best method for user-defined ordering of pages and entries is to sort by authored_on date.

Entries:

<mt:Entries sort_by="authored_on">
    <!-- entry content here -->
</mt:Entries>

Pages:

<mt:Pages sort_by="authored_on">
    <!-- page content here -->
</mt:Pages>

The authored_on date for entries can easily be updated using the “batch edit” functionality in the “More actions…” menu on the Manage Entries listing screen.

Because pages are listed by modified_on the “batch edit” functionality also uses the modified_on date. This is bad because the next time the page is saved, the modified date will be updated. (I submitted a bug about this some time ago.).

So follow along as we make a few changes to two Movable Type application templates to update Manage Pages screen (and the batch edit functionality for pages) use the authored_on date instead of the modified_on date.

Note: We could just update the batch edit mode to use the authored_on date, but it would be more useful to update the Manage Pages screen to also use the authored_on date so that pages will be listed in the same order they will appear in the templates.

These steps were tested in versions MT4.32 and MT4.261 but will work for all versions of MT4.x and MT5.0 as well.

Tip: Always make a backup of a default file before modifying it; I duplicate the file and place a ~ after it:

cp file.mtml file.mtml~

Two App Templates to Edit

$MT_HOME/tmpl/cms/include/entry_table.tmpl

One change repacing the table header label:

  1. Search for (line 79):

    <th class="date"><mt:if name="object_type" eq="page"><__trans phrase="Last Modified"><mt:else><__trans phrase="Created"></mt:if></th>
    

    Replace with:

    <th class="date"><__trans phrase="Created"></th>
    

$MT_HOME/lib/MT/CMS/Entry.pm

Three changes replacing modified_on with authored_on where conditioning based upon $type eq 'page':

  1. Search for (line 547):

    $arg{'sort'} = $type eq 'page' ? 'modified_on' : 'authored_on';
    

    Replace with:

    $arg{'sort'} = 'authored_on';
    
  2. Search for (line 1726):

    $entry->modified_on($ts);
    

    Replace with:

    $entry->authored_on($ts);
    
  3. Search for (lines 1988 and 1989):

    if ( my $ts =
        ( $type eq 'page' ) ? $obj->modified_on : $obj->authored_on )
    

    Replace with:

    if ( my $ts = $obj->authored_on )
    

Once these edits have been made, login to Movable Type and view the Manage Pages screen. All pages will be listed by created_on date.

That’s it!