Building a Template


Creating a new template can be done in either of a couple of ways. You can build a template from scratch by creating the page layout and then saving it as a template, or you can create a template based on a page you have already built, which is a really nice feature. That means that you can go backward through any sites you have created in the past and update the pages so that they are based on a template.

Creating a Template from Scratch

Creating a template from a brand new page is the easiest way to build a template. To create a template, choose File, New from the menu bar. In the New Document dialog box, shown in Figure 27.1, choose the Template page category and then choose the platform on which you want your base page developed. Click Create to build the blank page.

Figure 27.1. The New Document dialog box enables you to create a template.


Although the resulting page may look like any other new page, Dreamweaver has added some code to indicate that this is a template.

Click the Code button on the Document toolbar to switch to the Code view and you can see some additional markup that has been added to the page. As you can see in Figure 27.2, Dreamweaver has added an editable region for the title so that the title of each page can be adjusted to reflect the page's contents. As you'll see in a bit, these editable regions are what make it easy to customize the content stored in templates.

Figure 27.2. This page may look like an ordinary blank page, but there's more going on behind the scenes.


Creating a Template from an Existing Page

If you already have a page that you want to convert to a template, doing so is pretty simple. The first thing you need to do is take a look at the page and determine which areas of the page will remain static and which need to be able to be updated. By default, every area of the new template is locked down so items such as navigational elements, logos, and links that are common to each page can be updated easily. Those areas that need be altered on each page such as text content, photos, and so on will need to be specified later as editable regions so that you can customize each child page.

After you know which areas should remain locked and which will become editable regions, open the page and choose File, Save As Template. In the Save As Template dialog box, shown in Figure 27.3, choose the site to which you want the template to be related, type a description of the template, choose a template name, and then click Save.

Figure 27.3. Set the settings for your new template.


Before the save process is completed, Dreamweaver asks whether you want to update the links in the document (see Figure 27.4).

Figure 27.4. Dreamweaver asks whether you would like to update the links located within the template.


This occurs because Dreamweaver is moving your page out of the root of the site and into a subfolder named Templates. That means that the relative links to graphics and pages need to be updated to reflect the template's new location. Click Yes and Dreamweaver does the rest. After the save is completed, you'll notice that the file is now named with a .dwt extension, which indicates that it is now a Dreamweaver template.

Designating Editable Regions

Regardless of whether you created your template from scratch or by converting an existing page, you now need to designate certain areas of the page as editable. When child pages are created from the template, these are the only areas that can be modified, so be sure you have planned carefully.

To designate an area as an editable region, select the area (usually a cell within a table) and choose Insert, Template Objects, Editable Region from the menu bar. As shown in Figure 27.5, the New Editable Region dialog box asks you to provide a name for the new region. Type a name and click OK.

Figure 27.5. Designate a name for your editable region.


Tip

When naming your editable regions, set up a naming convention that you will use throughout all your templates. One suggestion is to use "er" as the prefix, so when looking at your code you would recognize something named erPageContent as an editable region of a template.


After the editable region has been placed in the page, a placeholder is inserted, marked by the name that you specified. You can enter any text or placeholder content that you'd like in that editable region, and it will be used as the default for any child pages that are created. So if you have a content editor that might add information to your page designs, you might type something like Add your page content here to indicate that this is the area to type information or add images.

Creating Optional Regions

Another type of template region is called an optional region. These regions hold content that may or may not be visible on every page, depending on whether or not you want to show it. For instance, suppose some of your pages have an image in the main content area. Some pages might not have a corresponding image, so you would want to be able to turn the image on for some pages and off for others. Enter the optional region.

Designating an area as optional is just as easy as creating an editable region. To choose the area, select Insert, Template Objects, Optional Region from the menu bar. In the New Optional Region dialog box, shown in Figure 27.6, type the name for the region and choose whether you want the region visible by default on child pages.

Figure 27.6. Create a name for your optional region.


If you want to enhance automation of your optional region's visibility, you can click the Advanced tab and specify an expression that triggers whether or not the region is visible. Click OK to create the new region in your page.

Note

For a great tutorial on using expressions to control template regions, check out the Macromedia TechNote at http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_16317.


Creating Repeating Regions

Repeating regions are those over which you want to give your content editor control to duplicate. For instance, if you were to create a table with two rows in an editable region, the content editor would be able to type in those two rows, but not add any additional rows. If, however, you made the rows repeating regions, the content editor would be allowed to create new rows because the new rows are exact duplicates of the data that is in the repeating region.

For instance, a blog would be a perfect example where a repeating region might be appropriate. As the web developer, you could create a template for the pages that contain the blog and lock down every aspect of the page except the repeating region where the content editor is to make periodic entries. Because the region is set to repeating, they would be able to create new entries at their convenience without ever worrying about adversely affecting the site design.

To create a repeating region, choose Insert, Template Objects, Repeating Region from the menu bar. Type a name for the repeating region and click OK.

Setting Object Attributes As Editable

An additional template tool that is available for your use enables you to allow certain objects within a template to have editable attributes. Objects that you can specify as having editable attributes include tables, images, layers, or Flash movies. For instance, if you want to place an image placeholder in your template that requires the URL to be editable on each child page, you could add the placeholder and make only the URL editable.

To set an object's attribute as editable, select the object and then choose Modify, Templates, Make Attribute Editable from the menu bar. In the Editable Tag Attributes dialog box, shown in Figure 27.7, select the attribute that you want to edit and click the Make Attribute Editable check box. Specify the appropriate label, type, and default and click OK.

Figure 27.7. Choose the attribute and values that you want to be editable in your child pages.


After the attribute has been set to editable, you should be able to view that attribute in the Property Inspector and see that it has been replaced by special code such as @@name@@. This markup indicates to the template that this is an editable attribute in any child pages.



Special Edition Using Macromedia Studio 8
Special Edition Using Macromedia Studio 8
ISBN: 0789733854
EAN: 2147483647
Year: 2003
Pages: 337

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net