Assign a template to a document

Based on https://ask.libreoffice.org/en/question/69314/how-do-i-assign-a-template-to-a-document/?answer=230862#post-id-230862 that did not work for me …

I created several “templates”, all based on a master where the styles and header/footer is defined. I need my other templates to be a flow down of the changes. Copy and Paste does not work with input filed requested when you open a template. (This is easy to do in Word and a feature request since the extension was broken with version 4.X per search. Also, the following does not exist anymore in the menu option File▸Templates▸Assign Template to Current Document

Example in my case

  • Master Template - Revamp header/footer and styles to new branding standards.
  • Letterhead - Uses Master Template (File▸Properties▸General tab ▸Template is Blank) and is “programed” with input fields
  • Proposal- Uses Master Template (File▸Properties▸General tab ▸Template is Blank) and is “programed” with different input fields from letterhead (e.g. invoice number)

All “sub” templates had originally used the master template. Redoing all the templates, literally from scratch, is counter intuitive to how a computer program’s template feature is supposed to work

Also, I tend to use the Portable App version, so relative links are preferred

Also, the following does not exist anymore in the menu option File▸Templates▸Assign Template to Current Document

It has never existed in plain LibreOffice. This menu item appears from the TemplateChange extension.

I wouldn’t read everything already posted here, but only point to one fact:
You cannot simply assign a different template with any software without mapping the styles defined in the document to the styles defined in the template (and reversely) probably needing to create additional styles in the document.
You can import the styles from a template (or from a different document) assuming the equally named styles in the document shall be updated to the styles from the template/otherDoc.
Menu path :>Styles >Load Styles...
If you also want to get prompted for updateing if the used template was changed, it may be necessary in addition to run

Sub changeTemplateTo(Optional pNewTemplateFilePath As String)
newTemplateURL       = ConvertToURL(pNewTemplateFilePath)
docProps             = ThisComponent.DocumentProperties
docProps.TemplateURL = newTemplateURL
End Sub  

(I’m not sure if also unused styles will be imported. Simply try)

Just checked my preserved LibO V3.6.5. There was no menu path >File>Templates>Assign Template to Current Document or similar.
@ElSid: If you mention a bug report (may be a feature request), please always link to it using the automatically linking format “tdf#nnnnnn” where the "n"s need to be replaced with the bug’s number.

I see to aspects to your question:

  • design a hierarchical tree of templates
  • changing template for a document

#Template hierarchy

This is presently not possible because a LO document stores only one template. Additionally (IMHO), implementing a recursive inclusion to resolve the hierarchy relation(s) would be a nightmare for little benefit in the majority of cases.

Since end-users are not supposed to see the “subtleties” of template design (their dependencies), you may accept a somewhat tedious maintenance procedure with two levels.

  • At the fundamental level, you only manage your primary template and the various secondary (dependent) templates (business letter, internal note, technical document, …). Here the secondary templates are only seen as ordinary documents. Put everything in a separate private directory.

    • To hide the primary template from users, don’t record it with File>Templates>Manage Templates. Save it as an *.ott. in this directory (don’t use File>Templates>Save as Template which would otherwise save it in the public directory).

    • Double-click on the primary template icon to create your secondary templates. Note that with this method, the documents don’t keep their relation with the template.

    • To circumvent this hindrance, assign the primary template to the documents with DocumentTemplateChanger extension. Remember to save your secondary “templates” as ordinary .odt documents.

    Now your secondary “template” documents can be automatically updated whenever your open them after a change in the primary template.

  • The second level deals with user-visible templates.

    Open your secondary “templates” documents and File>Templates>Save as Templates.

    CAUTION! From my experience, it is better to delete first an existing template before replacing it, otherwise you’ll end up with duplicate entries in the management window. This may be a bug, but deleting before replacing avoids the trouble. You can also ignore the various warnings about already existing categories (again this may be a bug but I didn’t search the bugs site about it).

    Your users will see only the secondary templates. The update process is separate from main line and is under your responsibility.

#Assigning a template to a document

  • To assign a template to an existing document or change the already assigned one, use the DocumentTemplateChanger extension.

    EDIT 2020-02-25 More information about the extension in my answer for this question.

  • To create a templated document from scratch, File>New>Templates

To show the community your question has been answered, click the ✓ next to the correct answer, and “upvote” by clicking on the ^ arrow of any helpful answers. These are the mechanisms for communicating the quality of the Q&A on this site. Thanks!

In case you need clarification, edit your question (not an answer which is reserved for solutions) or comment the relevant answer.

Template hierarchy

This is presently not possible because a LO document stores only one template.

Perhaps, I don’t understand your point, but there is a sort of hierarchy in templates. You can create a document form a template and save it as another template. The child template, obviously, inherits things from the parent template. If you edit the parent template and then open the child template for editing, you will be prompted to confirm updating it from the parent template. If you accept, the child template will update. And if you open a document created from the child template, it will update, too.

@gabix: if you have primary.ott → secondary.ott → document.odt, a change in primary.ott doesn’t propagate to document.odt. You must first update manually secondary.ott to get the update dialog on document.odt opening.

Whenever you open an .ott template, you get a blank document based on this template. The link between the primary and secondary templates is lost during this .ott.odt transformation. Even if you opened the .ott for update purpose, you won’t get it I could not check if the link between primary.ott and secondary.ott is present in the XML because you can only save documents (not templates) as .fodt. This is why I recommend the 2-layers approach, keeping the derived templates as ordinary documents for purpose of updating when the primary template changes.

If you know any trick allowing to open an .ott as a template (not as a blank document), I’d be glad to test it.

trick allowing to open an .ott as a template (not as a blank document),

If you mean opening for editing, there are at least two options:

  1. Right click on an OTT file in the file manage, choose Open (instead of New).
  2. File → Templates → Manage Templates, right click on a template → Edit.

@gabix: method 1 does not work (at least with my Fedora Linux), I get a blank document based on the template. Method 2 is not applicable when templates are located in “unusual” directories.

Method 2 requires meticulous care to base a template on another template. I get the update prompt but when I create a new document, the update seems to have had no effect. I checked right after the update in the child template while editing it, the styles were not changed per the ancestor template.

I think my contorted suggestion is the only way to go for hierarchical templates.

Quoting @gabix: “If you edit the parent template and then open the child template for editing, you will be prompted to confirm updating it from the parent template. If you accept, the child template will update.”

Are you sure? I also thought so without remembering concrete experience. But when I just tried to confirm this with LibO 6.4 opening the secondary template for editing I was not not prompted for updating styles after a change in the font of the (used!) default paragraph style of the base template. The styles were left unchanged without notice.

Lupp, I am pretty sure because I do it very often having a main template and a set of secondary templates. I don’t use 6.4 so far though, thus, you might have caught a regression bug.