Hacks : Custom Entry Preview 1.1 May 30 2003 | # | C:0

Custom Entry Preview 1.1

May 30, 2003 - updated February 8, 2006

If you use the MTMacro plugin to process the content of your entry, the standard MovableType Entry Preview may not show the entry the way you would expect it to.

This hack allows you to customize how the Entry Preview is formatted. It works by searching your blog for a template with the name “cms_entry_preview”. If it finds it, it uses the template to render the entry preview. Otherwise it uses the default preview that ships with MovableType.

lib/MT/App/CMS.pm Modification

The first part of the hack requires you to modify the CMS.pm file. This will cause MT to look for your custom template.

  1. Open the file CMS.pm located in the MovableType/lib/MT/App/CMS.pm directory.
  2. In the function preview_entry() find the following section:
        my $preview_code = <<'HTML' unless($preview_code);
  3. Replace this section with the following code:
    ### BEGIN Custom Entry Preview HACK
    ### http://www.nonplus.net/software/mt/CustomEntryPreview.htm
        $ctx->stash('blog_id', $blog_id);
        my $preview_code;
        require MT::Template;
        if(my $tmpl = MT::Template->load( { name=>'cms_entry_preview', blog_id => $blog_id })) {
            $preview_code = $tmpl->text;
        $preview_code = <<'HTML' unless($preview_code);
    ### END Custom Entry Preview HACK

Creating an Entry Preview Template

The second part involves creating the custom template. The template shouldn’t contain the <html> header, etc.—only the text that is going to display the entry.

In the Blog Templates page, create a new Template Module and give it the name cms_entry_preview. You can use the usual MT tags to design your preview. For example, if you want to apply the SmartyPants filter to the entry preview, you could use the following template:

Create a template module named cms_entry_preview. The module should only contain tags that are going to be inserted in the preview page (i.e. it should not include the <html> header, etc.) For example, to apply the SmartyPants plugin in your preview, you might use the following cms_entry_preview template:

<p><b><$MTEntryTitle smarty_pants="1"$></b></p><br />
<$MTEntryBody smarty_pants="1"$><br />
<$MTEntryMore smarty_pants="1"$>

After you save the template, go to an existing entry or create a new entry and click on the Preview button. The template should be rendered using your custom template.

Version History

  • Version 1.1 - July 7, 2003

    Added require MT::Template; and removed duplicate code.
  • Version 1.0 - May 30, 2003

    Initial Hack
The site database appears to be down.