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 very much like it, are posted almost daily to the OpenOffice.org User's list. Half the time, the problem is that senders have never heard of templates. The other half of the time, the senders are expecting templates to behave the same as in other office suites – and they don't. In both cases, the solution is to learn how OOo templates behave so that you can work with them instead of against them. Some template behavior in OOo may seem quirky, and at least one is a bug, but all of them are worth knowing. Once you do, you'll 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 .sxw for a regular document. Similarly, in Calc, the template extension is .stc.

Since 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 can also contain an outline for the contents, especially in Draw, whose autopilot allows you to select one template for format and another for the outline. However, most of the tools for templates assume that 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 that 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 less than half a dozen templates will cover over three-quarters of their needs in any OOo application. For example, a student might find that templates for essays, lab reports, job applications and letters home are all they need in Writer. 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, so that basic preferences for margins and fonts are 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 will soon become clear, this demand causes 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, fields, and fields. Things that cannot be saved in a template are those that are stored in OOo rather the document: for example, autotext, or any of the gradients and other options 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 that you include one paragraph of each outline level in the template. Otherwise, the settings for this particular tool are lost.

More importantly, the first time that a template is saved, be sure that 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 these ways are not listed in the Template Management system, even if placed in the template directories. Even worst, documents created with templates saved in these ways are not linked to the templates for automatic updating. Instead, save templates using File > Templates > Save. If you forget and go the logical route, then you 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, just not for the first.

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, and a path for the individual user. You can navigate the virtual directory freely, but 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 that 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 from other office suites.

In OOo, templates are governed by four basic rules:

OOo templates can never – under any circumstances – be altered by changes to any document based upon 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 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 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, 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 can also delete the template then replace it with another with 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 still applies.

The template determines the initial format for a document, but, beyond that, documents can be independent of formats. If you're trying to keep all your documents of a certain type looking consistent, you should make all changes to formatting in the template, 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, then the document is no longer linked to the template in any way. (If you accidentally don't update, then you should immediately close the document without saving, 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 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 are frequently surprised when other documents seem to spontaneously reformat when opened. Then, just 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 – and 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 can even be file corruption.

Of course, these problems can be avoided by a few simple precautions consistently applied. However, as with security measures, most people don't observe 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 are virtually 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.

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

Bruce Byfield was product manager at Stormix Technologies and marketing and communications director at Progeny Linux System. He also was a contributing editor at Maximum Linux and the original writer of the Desktop Debian manual. Away from his computer, he listens to punk-folk music, raises parrots and runs long, painful distances of his own free will.

Public Documentation License Notice

The contents of this Documentation are subject to the Public Documentation License Version 1.0 (the "License"); you may only use this Documentation if you comply with the terms of this License. A copy of the License is available at:

http://www.openoffice.org/licenses/PDL.html.

Note: The text of this appendix may differ slightly from the text of the notices in the files of the Original Documentation. You should use the text of this Appendix rather than the text found in the Original Documentation for Your Modifications.

The original Documentation is “Bullet-Proof Templates.” The Initial Writer of the Original Documentation is Bruce Byfield, Outlaw Communications. Copyright © 2004. All Rights Reserved. bbyfield@axion.net. 604-421.7177.

The article was originally published in March 2004 on the web site of the Linux Journal. The text has been lightly edited and modified by the writer for release under the OpenOffice.org PDL.

1825 words

Bruce Byfield / /5

5	Bullet-Proof Templates	Bruce Byfield

Bruce Byfield	Bullet-Proof Templates	5

2004-04-10T14:14:24