Bullet Proof Templates in OpenOffice.org
How templates function differently in OpenOffice.org than they do in other office suites, and why OpenOffice.org's are better.
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 of the time, the problem is the user have not heard of templates. The other half of the time, the users are expecting templates to behave the same in OpenOffice.org as they do in other office suites--but 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 OOo's Writer, the template extension is .stw as opposed to the .sxw extension used for a regular Writer document. Similarly, in Open Document format, the default format used in OOo version 2.0 and higher, the template extension for Writer is .ott.
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 feature is especially helpful in OOo's 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 some users are unaware of the fact, what they want is not to avoid using templates but changing 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 is. 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 option located in the list of commands found in File -> Templates -> Organize. For later template 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.
Currently, too, the Template Management system has a bug that disables saving any slideshow templates to the Presentation Background and Presentations folders. This bug prevents you from choosing any new templates when running the Impress templates.
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 other office suites.
In OOo, templates are governed by four basic rules:
- 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.
- 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 OOo source code and recompile it 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.
- 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 with different formatting, or you can copy and paste the document into the new template. Still, no matter how you work around it, the "only one" rule applies.
- 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 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 to a document that is not found in the template. 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, 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. Much the same rules apply when you are sharing a document with someone else.
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 still. 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 of 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.
Another advantage of these rules is they simplify file sharing. If you send a file to others once, you don't need to worry about sending the template. If the recipients have templates with the same name but different formats from the one used by the document, all they need to do is decline to update the file when they open. However, if you are sharing a file back and forth regularly, then each recipient should have the same template installed and receive any updates to it. Otherwise, either the document will be reformatted on each machine, which may complicate editing, or someone may break the connection to the template.
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.
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs2.5 License.
This article originally was published on March 14, 2004, on the Linux Journal Web site. It has been updated to reflect changes in OpenOffice.org since then and in response to readers' comments about the original article.
About the Author
Bruce Byfield is a computer journalist and course designer. His articles appear regularly on the Linux Journal and Newsforge Web sites.