Reusing Content with Templates and Libraries > Creating documents based on templates

 

Creating documents based on templates

You can use a template as a starting point for a new document, or apply a template to an existing document.

When you create a new document based on a template, you can choose whether the document will remain attached to the template. By default, when you change a template, a document based on that template is updated to reflect changes in the template. But if you deselect the Update Page When Template Changes option in the New from Template dialog box, the new document is created as stationery: a copy of the template that's an independent HTML file, with no locked or editable regions. In that case, updating the template does not change the document. In other words, deselecting this option is equivalent to creating a new document based on a template and then detaching the document from the template.

Note: The option of not updating the document when the template changes is provided for those who want to use templates like stationery files—a one-time starting point, to create completely independent documents. If you want to use Dreamweaver's default template behavior, in which documents based on a template are updated when the template changes, leave the option selected.

To create a new document based on a template, do one of the following:

Choose File > New from Template. In the dialog box that appears, choose a template. (If you don't want your new document to update when the template changes, deselect Update Page When Template Changes.) Then click Select.
Choose File > New to create a new document, and then apply a template to it by selecting a template in the Templates category of the Assets panel and clicking the Apply button. (Alternatively, you can drag a template from the Assets panel to the document.)

To apply a template to an existing Dreamweaver document:

Open the document. Then do one of the following:

Click in the Document window's Design view, then choose Modify > Templates > Apply Template to Page. Choose a template from the list and click Select.
Select the template in the Templates category of the Assets panel, and click the Apply button.
Drag the template from the Templates category of the Assets panel to the Document window's Design view.

Note: Saying that a template has been applied to a document is equivalent to saying that the document is based on the template. Those phrases are used interchangeably.

When you apply a template to an existing document that isn't already based on a template, Dreamweaver turns the document into a copy of the template file, placing the material from the document's existing body section into a single editable region of your choice.

Note: Behaviors and other scripts in the existing document that are associated with body content remain in the head section of the document after you apply a template to it. Other head items in the existing document, such as meta tags, are discarded when you apply the template.

When you apply a new template to an existing document that's based on another template, Dreamweaver turns the document into a copy of the new template, placing the material from the document's existing editable regions into corresponding editable regions of the new template wherever possible. Dreamweaver does this by comparing the names of the editable regions in the document to the names of the editable regions in the new template; for each region name that matches, Dreamweaver places the existing contents of that region into the new region with the same name.

For example, suppose you want to try out a new look for your site but you aren't ready to change all of your pages yet. You can create a new template with the new layout and design, giving the editable regions in the new template the same names as the editable regions in your old template; then when you apply the new template to one of your pages, the material in the editable regions of the page is placed in the corresponding editable regions of your new layout.

If there are editable regions in the old template that don't have corresponding regions in the new template, the Choose Editable Region for Orphaned Content dialog box asks you which new editable region the old "orphaned" content should be moved to. Choose an editable region name; all of the content from nonmatching editable regions is appended to the region you choose. (All of the orphaned content from the existing document must go into a single editable region.) If you select the (None) item instead of a region name, the content from nonmatching regions in the existing document is discarded.

If you think that the editable regions of your document match the editable regions of the new template you're applying, but the orphaned-content dialog box appears anyway, you can click Cancel and the new template will not be applied to the document. Then you can examine the editable regions in the document and the editable regions in the new template to find out which editable regions in the document do not appear in the new template. You can then add new regions with those names to the new template file.

Any new editable regions that are in the new template (but weren't in the old template) are added to the document. The new regions contain the default placeholder text given in the new template file.

After you've applied a template to a document, if the results aren't what you expected, you can use Edit > Undo Apply Template to revert to the document's state before the template was applied.