Creating Printer Friendly Versions of Blog Entries with Movable Type 4
October 24, 2007 | | Comments (8)

There are several methods available for creating printer friendly pages of websites but I’m only going to focus on one. Using Movable Type’s dynamic publishing option we can create on-demand printer friendly pages of weblog entries. Cool.

Roll up your sleeves because this method includes changing a blog’s publishing settings, creating a new archive template, archive mapping setting and adding links to an existing template module. It’s really not all that daunting but it was cool to maybe make it sound daunting and hard there for a minute.

Go to Preferences -> Publishing

Under Publishing Options find “Publishing Method” and change it to “Set each template’s Publish Options separately.”

Check “Enable conditional retrieval”

dynamic.png

Go to archive templates - > Create a new entry template

Let’s call the new template something like Print. For printer friendly pages I only want the my site’s header, entry title, entry date and entry body to print. I don’t want comments or trackbacks, sidebar content or footer content. So in my new Print template I only include the necessary archive variables and then code for the specific content as follows:

<MTSetVar name="body_class" value="mt-archive-listing mt-entry-archive">
<MTSetVar name="sidebar" value="1">
<MTSetVar name="module_about_context" value="1">
<MTSetVar name="body_onload" value="individualArchivesOnLoad(commenter_name)">
<MTSetVarBlock name="page_title"><$MTEntryTitle remove_html="1"$></MTSetVarBlock>

<$MTInclude module="Header"$>
    <b><$MTEntryTitle$></b><br/>
                <$MTEntryDate format="%x"$>

<MTIfNonEmpty tag="EntryBody">
        
            <$MTEntryBody$>
      
</MTIfNonEmpty>
<MTIfNonEmpty tag="EntryMore" convert_breaks="0">
        <div id="more" class="asset-more">
            <$MTEntryMore$>
        </div>
</MTIfNonEmpty>

Before saving make sure to click the box to Enable dynamic publishing for this template. After saving you’ll be able to edit the template’s archive mapping. This is important. This determines that address of your printer friendly page.

So click Create Archive Mapping, leave type set to Entry and choose add. After the archive mapping has been created we need to edit it to a custom address for our printer friendly pages. From the pull down menu select custom and edit it to your liking. This is the custom archive mapping that I’ve used:

%y/%m/%F/print/index.html

That mapping means the address for my printer friendly pages will looking something like: domainname.com/2007/10/entryname/print/.

mapping.png

Next we have to create a link to our printer friendly pages. In the entry metadata template module add the following code wherever you want your printer friendly link to be:

<a href="<mt:BlogArchiveURL><mt:EntryDate format="%Y/%m">/<mt:EntryBasename separator="-" />/print/">Printer friendly version</a>

One note about this code, notice the separator attribute with the mt:EntryBasename tag. By default mt:EntryBasename will spit out urls like so base_name.html. The problem is that my actual archive urls are base-name.html. See the difference? It’s underscore versus hyphen. Without the separator attribute the urls created by the mt:EntryBasename tag wouldn’t match the actual address of the printer friendly pages the new template is going to be creating.

Rebuild your entire site. Marvel at the magic of printer friendly pages.

As always if I've made any mistakes or if you have any questions please let me know.


Share this post:
digg del.icio.us reddit Newsvine Google Bookmark FaceBook Stumble Upon

8 Comments

cruv said:

I followed your instructions and it did not work, but I did find this bit of info that helped:
http://forums.sixapart.com/lofiversion/index.php/t63895.html

However, the separator="-" function is not working for some reason; the "Print This" URL keeps it as an underscore. Any thoughts?

Michelle Author Profile Page said:

No, I can't think of a reason the separator function wouldn't work. Have you completely rebuilt your site and reloaded it after implementing the separator function?

cruv said:

Yes, I've rebuilt it numerous times. I can not think of any reason why dynamic publishing wouldn't interfere...

I'll hack until it works or until I break it, then :)

Thank you for your time....

Rowan said:

I have looked high and low for how to do this, so thank you for detailing the information.

Unfortunately, I am having problems getting it to work. Depending on what I do, I get one of several error messages.

When I place the code in the entry metadata module as is I get:
Publish error in template 'Individual Entry': Error in tag: Error in tag: You used an 'MTEntryTitle' tag outside of the context of an entry; perhaps you mistakenly placed it outside of an 'MTEntries' container?

If I put in the tags, then the "Printer friendly version" disappears.

Once, it seemed to work, but then I got an error on trying to access the printer friendly version with an archive not found.

If I put the call coding in the entry detail module, then nothing shows either.

Am I missing something basic here?

Is a new print archive supposed to be created?
Why would I get the mtEntries error from the entry metadata?

Thanks.

Michelle Author Profile Page said:

It sounds like the order of the printer friendly link is out of sequence in your template. So you need to double check the entry detail template to see where the call for the entry metadata template is and make sure the sequence is right. You might check out the flattened templates section of the Movable Type manual: http://www.movabletype.org/documentation/designer/mt4-main-index-default-template-flattened.html

Rowan said:

I believe the error message came from a conflict with an earlier attempt at creating a printable format, so I removed all of that.

I then deleted everything from the first attempt at your strategy above. I now get a rebuild with no errors, and "printer friendly version" appears as expected.

However, I am confused as to what is supposed to happen then. Does this strategy create another set of archives? That is what I assumed it did, but the archive is not created. I get the following error message using the file mapping specified"
Page not found http://www.srwolf.com/wolfsoc/articlearchives/2008/01/food-prices-cheap-no-more/print/

So I decided to attempt creating a print archive, and changed the mapping to /print/%F AND I manually created /srwolf.com/wolfsoc/articlearchives/print and set the permissions to 777. Upon rebuilding the entire site, no entries were written and I get the following error message:
Page not found - /wolfsoc/articlearchives/2008/01/food-prices-cheap-no-more/print/

Which was not what I expected which SHOULD have been
/wolfsoc/articlearchives/print/food-prices....

What IS supposed to happen with the archive mapping, and are printer friendly copies of the entries supposed to be created?

Thanks

Rowan said:

After playing around with this a bit, I got it to work for me by making the following modifications:
Changing the separator in Entry Metadata string from
separator="-" to separator="_"

and changing the custom archive mapping for the Print archive from
%y/%m/%F/print/index.html
to
%y/%m/%-F/print/index.html

The problem I was having was a name mismatch between my standard base name which uses an underscore (_) and the custom mapping and Entry Metadata addition. Once I made them all consistent, the Printer friendly version displays correctly and the permalink entry also displays correctly.

You may see it at work at this link and select an entry to open to full screen. If you select both the permalink and the printer friendly link, you will see the differences in the display.

Michelle, thanks for the tutorial and the additional information!!!

Michelle Author Profile Page said:

You're very welcome. I'm glad you got it to work.

Leave a comment