OpenOffice Off-the-Wall: Bullet Proof Templates

by Bruce Byfield

"Where are my custom formats? I spent hours getting them right. Now, when I open a new document, they're gone."

This panicked cry, or ones similar to it, are posted almost daily to the OpenOffice.org User's List. Half the time, the problem is senders have not heard of templates. The other half of the time, the senders are expecting templates to behave the same in OpenOffice.org as they do in other office suites--they don't.In both cases, the solution is to learn how OOo templates behave so you can work with them instead of against them. Some template behaviors in OOo may seem quirky, and at least one of them is a bug, but all of them are worth knowing. Once you do know them, you should find that the way OOo handles templates reduces the chances of problems and conflicts and makes documents more portable.

What's a Template?

In technical terms, a template is any OOo document with a t as the second character of its extension. For example, in Writer, the template is .stw, as opposed to the .sxw extension used for a regular document. Similarly, in Calc, the template extension is .stc.

Because this definition doesn't get us very far, let's try again. A template is a document whose design can be used by other documents of the same kind. A template also may contain an outline for the contents. This is especially helpful in Draw, whose Autopilot feature allows you to select one template for format and another for the outline. However, most of the tools for templates assume you are using them for design.

By using a template, you avoid having to design every document from scratch. Instead, you can select a template from File -> New -> Templates and Document and immediately start thinking of content. Templates are especially handy if you are working with a group of documents that should all look the same.

Every now and again, a few posters on the OOo User's List pop up to say they can't possibly use templates, because every document they do is unique. In practice, however, that is rarely true. With some intelligent planning, most users find that fewer than half a dozen templates can cover over three-quarters of their needs in any OOo application. For example, a student might find that templates in Writer for essays, lab reports, job applications and letters home are all they need. For an executive, the templates might be memos, faxes, letters and reports. And, even for unique documents, the average user is likely to want to set a default template that makes basic preferences for margins and fonts immediately available.

In fact, using templates is so much a part of the logic of OOo that even those who resist using templates cannot avoid them. Although they are unaware of the fact, what they want is not to avoid using templates, but to change the default template at will. However, as should soon become clear, this demand creates far more problems than convenience.

Setting Up a Template

Templates in OOo are designed in the same way as any other document. Virtually everything that can be customized in a document can be saved in templates, including document properties, styles and fields. Things that cannot be saved in a template are those items stored in OOo rather than the document itself. This list includes autotext and any of the gradients and other options used for the background of a draw object.

Once you are finished designing, you are ready to save, and that's where the quirkiness crops up. To start with, if you want to save the settings in Tool -> Outline Numbering, be sure to include one paragraph of each outline level in the template. Otherwise, the settings for this particular tool are lost.

More importantly, the first time a template is saved, be sure you don't save it using File -> Save or Save As. Even though these tools include the option to save as a template, a few necessary lines of XML code are not added to templates saved in this way. As a result, templates saved in this way are not listed in the Template Management system, even if they are placed in the template directories. Even worse, documents created with templates saved in this manner are not linked to the templates for automatic updating. Instead, save templates using File -> Templates -> Save. If you forget and go the logical route, you then can use the Import Templates options in the list of commands in File -> Templates -> Organize. For later saves, File -> Save or Save As are fine; they simply don't work for the first save.

The Template Management system, incidentally, is another quirk. It's a virtual directory created from the paths set in Tools -> Options -> OpenOffice.org -> Paths -> Templates. The default paths include a general path for a single- or multiple-user installation, plus a path for the individual user. You can navigate the virtual directory freely, but you cannot move outside it while inside the Template Management window. If you want a directory for sharing templates on a multiple-user system, either change the permissions on the general path so all users can write to it or add a public directory to the paths.

How Templates Work with Other Documents

Once you've designed a template, you can base other documents on it by selecting it from File -> New -> Templates and Documents. This is where the trouble really begins for new users, because OO templates interact with documents very differently from what they've learned to expect with from other office suites.

In OOo, templates are governed by four basic rules:

  • 1. OOo templates can never, under any circumstances, be altered by changes made to any document based on them. If you want to change a template, select the Edit command from the Template Management window.

  • 2. The template called Default (not to be confused with the template set as default, although it probably will be) cannot be altered at all from within OOo. So far as I can see, you would have to edit the source code and recompile before you could edit the Default template, and few users are going to bother. You can set another template as the default template for an application by using the Set as default template command in the Template Management window. But, the Default template itself is unaffected. Whenever you want, you can restore Default to the default template position by selecting the Reset Default Template command.

  • 3. Only one template can be applied to each document. If you want to add formats from another template, import them using Format -> Styles -> Load, and then update the document the next time you open it. If you want to change the template for a document, use the same procedure. You also can delete the template and replace it with another of the same name but different formatting, or copy and paste the document into the new template. Still, no matter how you work around it, the rule applies.

  • 4. The template determines the initial format for a document; beyond that, documents can be independent of formats. If you're trying to make sure that all of your documents of a certain type have a consistent look, you should make all changes to formatting in the template, and then reapply it to all linked documents. However, nothing stops you from adding formatting not found in the template to a document. Furthermore, the first time you open a document after its template is modified, you have one chance to add the modifications to the document. If you don't, then the document is no longer linked to the template in any way. (If you accidentally don't update, you immediately should close the document without saving and then reopen it, paying more attention this time to the on-screen messages.)

These rules are far from arbitrary. In fact, they seem designed to eliminate some of the common formatting frustrations in MS Office. In MS Office, changes to a document can update its template. In fact, most users routinely update their templates in this way. As a result, they frequently are surprised when other documents seem to spontaneously reformat when opened. Then, to compound the problem, users are generally reformatting the default template without realizing what they are doing. For this reason, the default template in MS Word is rarely identical on any two machines. With a shared or networked version, the mutations are stranger and more rapid yet. Applying multiple templates to this situation only adds to the confusion. The consequences are wasted time and inconsistency. In extreme cases, when the differences between the template and document become too large, the result even can be file corruption.

Of course, these problems can be avoided by applying a few simple precautions consistently. However, as with security measures, most people don't apply them.

By contrast, the behavior of templates in OOo eliminates all these problems without the need for special precautions. Templates are protected from accidental changes, and conflicts between templates or between templates and documents virtually are eliminated. Moreover, if the same fonts are available, you can be reasonably confident that what you see on your machine is what recipients of your documents will see on theirs, especially when the Default template is used.

The rules for templates in OOo are not perfect. In particular, methods for cleanly changing templates and for reapplying a template after a document is unlinked would be useful. However, these changes might not be possible without compromising the protection offered by the current arrangement. As things stand, the rules for templates in OOo ensure that your work is made easier without adding extra complications. Once you understand how these rules work and why, you'll appreciate them for the time-savers they are.

Bruce Byfield was a manager at Stormix Technologies and Progeny Linux Systems and a Contributing Editor at Maximum Linux. Away from his desktop, he listens to punk-folk music, raises parrots and runs long, painful distances of his own free will. He currently is writing a book on OpenOffice.org.

Load Disqus comments