Static to Template Conversion!
There are times when you take over a web site that was built totally static, in the sense that no templates were used in building it. As a professional web master, your idea is to convert the site to be template driven so that the design of the site stays consistent from page to page with minimal maintenance on your part, except for content. The question, though, is ... How do you do this on an existing site?
Let's cover a couple of issues first.
- ALWAYS (and we mean ALWAYS) have a backup of your site before doing anything of this nature to it. Be safe and be proactive!
- Dreamweaver MX has no way of determining which content goes into which editable region of the new template when applying a new template to a static site.
- Dreamweaver MX cannot apply a template to more than one page at a time, regardless of the method used.
How can you do it?
There are 3 basic methodologies that will accomplish the desired task. Which one you use will depend on your comfort level with Templates and the HTML tags that constitute a web page.
- You could use a site-wide Find and Replace to add the necessary template code to the pages, but it would still be difficult to apply the desired content to a targeted template region. In our opinion, this is potentially much more problematic than it is worth.
- You could use Apply Template to Page on every page and then perform extensive modifications to each to remove the static page's design elements such as header, sidebar and footer (if those are included in the template).
- You could use your template to spawn a new child page, and then use the visual Design view to copy and paste page elements into the newly spawned child page.
- You could use by far the easiest method with some of Dreamweaver MX's new template functions: Export Template Data as XML, modify the resulting XML page for content from each of the static pages, and then use Import XML into Template to apply each of the XML files to the Template in question, thereby converting your static site to a template driven web site. This method also allows for future page additions easily if the client sends you copy in text or word format.
What does all this mean?
What this means is that no matter which method you use to convert the site, it will take a little bit of work on your part, so it is prudent to consider the conversion method carefully. It may also make sense to consider reasonable alternatives, like Server-side Includes (SSI), which allow many of the advantages of DMX's templates. If the client will be updating content then locking part of the page with a template makes sense; if not, then the use of SSI may well make more sense :)
The XML Method...
- Create your desired template
- Save the template.
- Export Template as XML... this is an XML export of your document structure that you can use as a "pseudo-template" for all new content.
- Open this XML file in DMX and use copy/paste to lift code from your existing pages into the appropriate area of the XML CDATA fields.
- Save the modified XML file with a different name (representative of the final page name).
- Open a new child page based on the template (can be a blank document also, but a document of some sort MUST be open for the menu entries to become enabled for use).
- Use FILE | Import > XML into Template....
- Select the modified XML file from the UI.
- Save the newly generated child page with an appropriate name.
What you've learned
The advantage of the Import XML method is that you then ONLY have to work with content and not any existing navigation or layout information because you are able to manually filter it all out.
No matter the method used, you will have quite a bit of work ahead of you and it may be more beneficial for you in the long run to just simply recreate the site from scratch as the same amount of time will likely be spent regardless of method.
Our Book goes into detail about performing this function with existing data in Chapter 5, using the Export Template Data as XML and the Import XML into Template functions.