[ LiB ] |
Dreamweaver templates can also be used with dynamic pages. This lets you create an overall look for the site using templates and still dynamically generate individual pages.
This discussion assumes that you're familiar with template basics. If you're not, check out Chapter 20, "Site-Wide Content with Templates and Libraries." |
To create a dynamic template, choose File > New. In the New Document dialog box, shown in Figure 23.1, choose Template page and any of the dynamic document types listed. What's the difference between a dynamic and a normal HTML template? If you're using a server model that requires any directives to be added to the top of the page (such as the language declaration in ASP or ASP.NET), the code is added for you. Dreamweaver also saves dynamic template files with two file extensionssuch as main.cfm.dwt to indicate their status.
You can also create a dynamic template by opening an existing dynamic page and choosing File > Save as Template.
When a page is generated from a template, all areas are locked except for editable regions that have been specifically defined. Dynamic pages usually include server-side content that's defined outside the html tags. To accommodate this code, Dreamweaver templates consider the area outside the html tags to be editable by child pages. You can tell that this is happening by looking at the head area of any template child page, where you'll find this statement immediately following the html tag:
<!-- InstanceBegin template="/Templates/main.dwt" codeOutsideHTMLIsLocked="false" -->
This means that you can add recordsets and other server-side instructions to documents based on templates.
You can still add server-side instructions to the template page itself, but if any code is placed outside the HTML tag, it is treated just like content in any editable region: It isn't copied to existing child pages, and although it will be added to any new child pages created from now on, those pages can overwrite it. Dreamweaver warns you that this will happen, as shown in Figure 23.2.
If you want to keep the area outside the HTML tag lockedwhich means you want all child pages to use the same recordsets that the template usesyou can do so. By default, template files don't include a code-locking statement (this statement is added to the child pages only as they're created). But you can add one. In the template file, switch to Code view, and type the following code into the head section:
<!-- TemplateInfo codeOutsideHTMLIsLocked="true" -->
In this chapter's exercises, you'll work on an alternative version of the Antiques Barn site you worked with in the previous chapter. You don't need to have done any of those exercises to do these. But you do need to set up your workstation for dynamic development, using ColdFusion, PHP, or ASP.NET. You need to install the more_antiques database, in MySQL or Access format (it's in the chapter_23 folder on the book's website at www.peachpit.com), and, depending on your technology choice, you might need to define a driver. Read the instructions in Chapter 21, "Building Dynamic Sites with Dreamweaver," if you need refreshing on this.
Before beginning the exercise, from within the chapter_23 folder on the book's website, find the folder that matches your server model and language. Copy that folder to your hard drive, and define a site called Chapter 23, using it as the local root folder. Also set up a testing server for the site. You also must define a connection to the more_antiques database.
See Chapter 21 for a full discussion of setting up the testing server and defining a database connection. |
images/ bookcase _sm.jpg
This method of workingusing a basename to generate image pathsworks only if the image files and database fields are set up this way. Otherwise, thumbnail and full-size images are specified in separate database fields. For creating catalog pages, either method works. |
Save this file! You'll need it for another exercise later in this chapter.
What's in the more_antiques Database?The database used for the exercises in this chapter is a more sophisticated version of the antiques database used in the previous chapters. It contains more interrelated tables to create more of a real-world experience working with fully functional databases. Figure 23.5 shows the table structure as it appears in the Microsoft Access interface, with primary keys and table relationships diagrammed. Figure 23.5. The table structure of the more_antiques database.
|
[ LiB ] |