Reusing Content with Templates and Libraries > Creating templates > About links in templates |
To create a link in a template file, use the folder icon or the Point-to-File icon in the Property inspector; don't type in the name of the file to link to. If you type the name, the link may not work as expected. The following information explains why this problem occurs and provides an example of a situation in which you might encounter it.
When you create a template file by opening an existing page and then saving that page as a template, Dreamweaver ensures that all links in the page continue to point to the same files they pointed to before. Since templates are saved in a special template folder, this means that the path shown for a document-relative link changes when you save the page as a template. Don't be concerned about this change; when you create a new document based on that template, and then save the new document, all the document-relative links are updated to continue to point to the correct files, just as you would expect.
When you add a new document-relative link to a template file, however, if you type the path into the link text box in the Property inspector, it's easy to enter the wrong path by mistake. The correct path is the path from the Templates folder to the document you're linking to, not the path from the document folder.
To avoid this problem, use the folder icon or the Point-to-File icon to select files to link to. For information about linking using the Point-to-File icon, see Linking documents using the Property inspector and the Point-to-File icon.
The following example demonstrates the problem. Suppose you have a site in which individual catalog pages (called gadgets.html, gewgaws.html, and thingamajigs.html) are based on a template file called Catalog_Page.dwt. The site's folder structure looks like this:
Suppose you want each page based on the template to contain a link pointing to the file home.html. You open the Catalog_Page template to add the link, and you select the image that you want to attach the link to. But if you type home.html into the link text box in the Property inspector, you'll encounter the document-relative link problem: when you save the edited template, the documents based on the template will point to the wrong place, because the link in the template file is interpreted as relative to the Templates folder rather than relative to the Catalog folder. That is, the home.html link in the template file points to home.html in the Templates folder, instead of to ../Catalog/home.html. When Dreamweaver updates the documents based on the template, it modifies the document-relative links in the documents; for documents in the Catalog folder, a link in the template file to ../Catalog/home.html is converted to home.html, but a link in the template file to home.html is converted to ../Templates/home.html.
If you select the home.html file using the folder icon or the Point-to-File icon rather than typing its name manually, Dreamweaver automatically updates all documents based on the template to use the correct relative paths to home.html.
Note: In some cases (such as file paths in event handlers in templates) you can't use the folder icon or the Point-to-File icon; in those cases, be sure to enter the correct path by hand.