Sunday, January 27, 2013

6. Adding Code through the Snippets Panel


You can save portions of HTML code for easy recall in other files, using the valuable Snippets
feature. It’s a lot easier than copying and pasting blocks of code from various files. Tag snippets
range from a single tag, such as an HTML comment, to a full navigation layout. Commonly used
JavaScript and other language functions and methods are also good candidates to be turned
into a snippet for later use.
Dreamweaver provides a notable assortment of snippets, but the most important aspect of this
feature is that it’s extensible. Coders and noncoders alike can easily add any commonly used
section of code for later re-use. Snippets work in one of two different ways: A snippet either
inserts a solid code block at the cursor point or wraps a selection with before and after code.
The Snippets panel is found under the Code panel group; to open it directly, choose Window
➪ Snippets or use the keyboard shortcut, Shift+F9. The Snippets panel, shown in Figure 6-12,
shows a preview of the selected snippet. If the snippet itself is not rendered onscreen, like a
JavaScript function, the preview shows the code itself; otherwise, you’ll see exactly what the
code will look like on the page, minus any CSS stylings. Rearrange your snippets by dragging
them within the panel, from folder to folder, if you like.
To insert a snippet, follow these steps:
1. Display the Snippets panel if it’s not already open by choosing Window ➪ Snippets.
2. Find the desired snippet by expanding the folder and, if necessary, subfolders.
3. To insert a snippet as a block of code:
a. Position the cursor where you’d like the code to appear.
b. Double-click the snippet (or snippet icon) or select the snippet and choose Insert.
Alternatively, you can drag the snippet into position in either Code view or Design view.
New
Feature
Caution
Note
Chapter 6 ✦ Accessing the Code Directly 243
Figure 6-12: Use the handy Snippets panel to
quickly re-use portions of your code.
4. To wrap a snippet around some existing code or page elements:
a. Select the code or elements.
b. Double-click the snippet or select the snippet and choose Insert.
Again, you can drag the snippet onto the selected code.
You can quickly hide a section of a page by selecting it and then choosing the Comment,
Multi-line snippet from the Comments category of the Snippets panel.
While Dreamweaver’s standard code snippets are handy, the real value of the Snippets panel is
not realized until you begin adding your own. To help you manage your snippets, Dreamweaver
enables you to create new folders, rename existing ones, or delete ones no longer needed. All of
this functionality is available through the options menu on the Snippets panel as well as
through the context menu. Snippets, as well as folders, can be renamed, deleted, edited and, of
course, created.
Before you begin to create your own code snippet, select it first. The Snippets dialog box is
modal, and you cannot access other Dreamweaver windows while it is open. The selected
code is copied to the Insert Before text field.
To save code as a snippet, follow these steps:
1. Select the New Snippets button from the bottom of the Snippets panel.
2. Enter a name to be displayed in the Snippets panel in the Name field.
Tip
Tip
244 Part II ✦ Web Design and Layout
3. If you like, you can enter a brief description of the snippet in the Description field.
4. Choose the type of Snippet you’re creating: Wrap Selection or Insert Block.
The dialog box changes depending on your choice.
5. If you chose Wrap Selection, enter the code to appear prior to the selection in the
Insert Before field, and the code to appear after in the Insert After field.
6. If you chose Insert Block, enter the code in the Insert Code field.
If you switch from Wrap Selection to Insert Block, Dreamweaver appends the Insert
Before field with the contents of the Insert After field.
7. Choose how you would like the snippet to be displayed in the preview area of the
Snippets panel, rendered as in Design view or as code.
If you choose the Design preview option for code that does not display in a browser, such as
a JavaScript function, it won’t be as readable. You’ll still see the code in the preview area, but
it will not appear in a monospace font, and all whitespace formatting such as tabs will
appear to be lost.
8. Click OK when you’re done.
Snippets in Dreamweaver MX are not compatible with the snippets created by HomeSite,
ColdFusion Studio, or using Massimo Foti’s TMT Snippets Panel extension for Dreamweaver 4.
Massimo has, however, developed a converter that is available at www.DreamweaverFAQ.
com/Snippets/. If you have a number of snippets in any of these formats and you would
like to use them in Dreamweaver MX, be sure to pick up this invaluable utility. Speaking of
invaluable, you’ll find over 200 snippets ready for download at the DreamweaverFAQ site.
Using the Reference Panel
Pop quiz: What value of a form tag’s enctype attribute should you use if the user is submitting
a file?
A. application/x-www-form-urlencoded
B. multipart/form-data
C. multipart/data-form
Unless you’ve recently had to include such a form in a Web page, you probably had to pull
down that well-worn HTML reference book you keep handy and look up the answer. All code
for the Web—including HTML, JavaScript, and Cascading Style Sheets (CSS)—must be precisely
written or it will, at best, be ignored; at worst, an error will be generated whenever the
user views the page. Even the savviest of Web designers can’t remember the syntax of every
tag, attribute, and value in HTML or every function in JavaScript or every style rule in CSS. A
good reference is a necessity in Web design. (By the way, the answer to the pop quiz is B.)
Macromedia has lightened the load on your bookshelf considerably with the addition of the
Reference panel, shown in Figure 6-13. With the Reference panel, you can quickly look up any
HTML tag and its attributes, as well as JavaScript objects and CSS style rules. Dynamic site
builders can rely on references for CFML, ASP, and JSP. In addition, the panel contains
detailed information on Sitespring’s Project Site tags, as well as a complete reference on
Tip
Caution
Chapter 6 ✦ Accessing the Code Directly 245
Web-related accessibility issues from UsableNet. Not only does the Reference panel offer the
proper syntax for any code in question, in most situations it also displays the level of browser
support available. Moreover, you don’t have to dig through the tag lists to find the information
you need—just highlight the tag or object in question and press the keyboard shortcut,
Shift+F1.
Figure 6-13: To quickly look up a tag, select
it in the Tag Selector or in Code view and then
choose Shift+F1 to open the Reference panel.
You have four different ways to open the Reference panel:
✦ Choose Window ➪ Reference.
✦ Select the Reference button on the toolbar.
✦ Use the Shift+F1 keyboard shortcut.
To find reference details for the attributes of an HTML tag, a JavaScript object, or a CSS style
rule included on a Web page, open Code view and select the code in question prior to
choosing Shift+F1 or selecting the Reference button from the toolbar.
To look for information about code not included in the page, follow these steps:
1. Display the Reference panel by choosing Window ➪ Reference or using the keyboard
shortcut Shift+F1.
Tip
246 Part II ✦ Web Design and Layout
2. Select the required guide from the Book drop-down list. The standard options are as
follows:
• Macromedia CFML Reference
• O’Reilly CSS Reference
• O’Reilly HTML Reference
• O’Reilly JavaScript Reference
• Sitespring Project Site Tag Reference
• UsableNet Accessibility Reference
• Wrox ASP 3.0 Reference
• Wrox JSP Reference
3. Choose the primary topic from the Style/Tag/Object drop-down list. The list heading
changes depending on which Book is selected.
Windows users can move quickly to a topic by selecting the drop-down list and then pressing
the key for the first letter of the term being sought. Then they can use the down arrow to
move through items that start with that letter. For example, if you were looking for information
about the JavaScript regular expressions object, you could press “r” and then the down
arrow to reach RegExp.
4. If desired, you can select a secondary topic from the second drop-down list.
The second list is context-sensitive. For example, if you’ve chosen an HTML tag, the
secondary list displays all the available attributes for that tag. If you’ve chosen a
JavaScript object, the secondary list shows the available properties for that object.
The information shown depends, naturally, on the book, topic, and subtopic chosen.
The Reference panel’s context menu enables you to switch between three different font sizes:
small, medium, and large. This capability is especially useful when working at resolutions
higher than 800 × 600. You’ll also find an option to connect directly to O’Reilly Books Online.
Modifying Code with the Tag Inspector
Since Dreamweaver’s beginning, one of my favorite features has been the Tag Selector. I really
appreciated the precision it brought to the entire selection process. However, the Tag Selector
is not without its drawbacks. The feature’s main deficiency is key to its design—the Tag
Selector only displays the tags enclosing the current position of the cursor. As pages have
become increasingly complex, it’s not always easy to see where you are on the page with the
Tag Selector. To give developers a better handle on the overall structure of a page—without
sacrificing any attention to detail—Dreamweaver has introduced the Tag Inspector.
The Tag Inspector actually has a three-fold function. First, the panel displays an overview of
the page in a collapsible tree structure. You can expand the page elements to drill down as far
as necessary or collapse them to get an overall sense of the page. Second, it’s a navigation aid.
Use the Tag Inspector to quickly select any element anywhere on the page. Finally—and I
saved the best for last—the Tag Inspector is like a Property inspector on steroids. Select any
tag, and all the possible attributes for that tag are displayed—and ready for editing—in the
panel’s lower portion. Not only does the Tag Selector make it extremely easy to check a tag’s
attributes at a glance, but it also puts all of an element’s properties right at your fingertips.
New
Feature
Tip
Chapter 6 ✦ Accessing the Code Directly 247
Like the Snippets panel, the Tag Inspector is found under the Code panel group. To directly
open the Tag Inspector, choose Window ➪ Tag Inspector. You can select tags in several ways:
✦ Locate the tag in the tree view of the Tag Inspector.
✦ Highlight the tag in Code view or in the Code inspector.
✦ Choose the tag in the Tag Selector, shown in Figure 6-14.
Figure 6-14: Use the Tag Inspector to quickly
modify any or all attributes of any tag on
the page.
Once a tag is selected, enter or change values for attributes in the Tag Inspector’s list view.
Values may be entered directly as text or, in some cases, with the aid of a Dreamweaver dropdown
list or two. For example, the bgcolor attribute for the <td> tag offers a color picker as
well as a connection to dynamic data. Other helpers include a drop-down list of preset values
and a point-to-file icon.
Unlike the Tag Chooser, the Tag Inspector does work with custom tags and attributes entered
through the Tag Library Editor.

5. Working with Code View and Code Inspector


Although Dreamweaver offers many options for using the visual interface of the Document
window, sometimes you just have to tweak the code by hand. Dreamweaver’s acceptance by
professional coders is due in large part to the easy access of the underlying code. Dreamweaver
includes several methods for directly viewing, inputting, and modifying code for your Web page.
For large-scale additions and changes, you might consider using an external HTML editor such
as BBEdit or Homesite, but for many situations, the built-in Code view and Code inspector are
perfectly suited and much faster to work with.
Code view is one of the coolest tools in Dreamweaver’s code-savvy toolbox. You can either
view your code full-screen in the Document window, split-screen with Design view, or in a
separate panel, the Code inspector. The underlying engine for all Code views is the same—
and, for Dreamweaver, the code editor has had significant enhancements made to the feature
set and performance.
You can use either of the following methods to display the full-screen Code view:
✦ Select View ➪ Code.
✦ Choose the Show Code View button from the toolbar. Code view is displayed, as shown
in Figure 6-7.
You can access the split-screen Code and Design view with any of the following methods:
✦ Choose View ➪ Code and Design.
✦ Select the Show Code and Design Views button on the toolbar.
✦ Press Ctrl+` (Command+`) when in Design view and the Code inspector is closed. The `
character is the grave accent paired with the tilde (~) on keyboards.
Caution
Chapter 6 ✦ Accessing the Code Directly 235
Figure 6-7: Code view.
To change the relative size of the Code and Design views, drag the splitter bar up or down. In
the split-screen Code and Design view, Code view is shown on top of the Design view. You can
reverse that order by choosing View ➪ Design View on Top or selecting Design View on Top
from the View Options button on the toolbar.
You have several ways to open the Code inspector:
✦ Choose Window ➪ Code Inspector.
✦ Select the Show Code Inspector button in the Launcher.
✦ Use the keyboard shortcut F10.
Once opened, the Code inspector (see Figure 6-8) behaves like any other floating panel in
Dreamweaver: The window can be resized, moved, or hidden, and the inspector can be
docked above or below the Document window or dragged out onto its own panel. When the
Code inspector is opened initially, it is automatically selected. If you click in the Document
window with the Code inspector open, the inspector dims but still reflects changes made in
the document.
In all Code views, Dreamweaver does not update the Design view of the document
immediately—whereas changes in Design view are instantly reflected in any open Code
view. This delay is enforced to enable the code to be completed before being applied. To
apply modifications made in the code, switch to Design view; if Design view is open, click
anywhere in it to give it focus. Should Dreamweaver detect any invalid HTML, such as an
improperly closed tag, the offending code is flagged with a yellow highlight in both Design
and Code views. Select the marked tag to see an explanation and suggestions for correcting
the problem in the Property inspector.
236 Part II ✦ Web Design and Layout
Figure 6-8: To update Design view while still working with the Code inspector, select the
handy Refresh button—either on the toolbar or the Property inspector—or choose F5.
You can also apply code changes to Design view by saving the document or by choosing the
Refresh button on the toolbar or the Property inspector. The Refresh button becomes active
only when modifications are made in any Code view. You also have a keyboard and menu
alternative: pressing F5 has the same effect as choosing View ➪ Refresh Design View.
Generally, the Code view and Code inspector act like a regular text editor. Simply click anywhere
in the inspector to add or modify code. Double-click a word to select it. Select an entire
line by moving your pointer to the left edge of the code—where the pointer becomes a rightpointing
arrow—and clicking once. Multiple lines can be selected in this same fashion by
dragging the right-pointing arrow. Once a section of code is selected, you can drag and drop it
into a new location; pressing the Ctrl (Option) key while dragging makes a copy of the selection.
Moving from word to word is accomplished by pressing Ctrl (Command) in combination
with any of the arrow keys.
Enabling Code view options
Some special features in Dreamweaver’s code editor simplify the task of writing HTML and
other types of code. When in any Code view, some of these features can be toggled on and off
by choosing the command either from the View ➪ Code View Options list or under the View
Options button on the Document toolbar:
✦ Word Wrap: Wraps lines within the boundaries of the Code view window or Code
inspector to eliminate the need for horizontal scrolling.
Chapter 6 ✦ Accessing the Code Directly 237
✦ Line Numbers: Displays a number for every line in the code; this feature is extremely
helpful when used in combination with the JavaScript Debugger, which reports the line
number of an error in the code.
✦ Highlight Invalid HTML: Toggles the highlighting of invalid tags in Code view when
Design view is refreshed. Invalid tags are always highlighted in the Design view.
✦ Syntax Coloring: Syntax coloring makes code easier to read. Basic tags and keywords
are shown in one color, with text in another color. Three different types of code are
given different colors: Reserved Keywords, Other Keywords, and Strings. These
colors are set in the Code Color category of Preferences. You can also set a color for
an individual tag to further distinguish it if you like.
✦ Auto Indent: Auto Indent is another feature intended to improve code readability. With
Auto Indent enabled, pressing Enter (Return) at the end of a line causes the new line to
start at the same indentation as the preceding line. Press Backspace (Delete) to move
the indented line closer to the left margin. The number of characters for each indentation
is set in the Code Format category of Preferences.
You can also easily change the indentation—in or out—for selected blocks of code. To
further indent a block of code, select it and then choose Tab. To decrease the level of
indentation for a selected code block, choose Shift+Tab. Alternatively, you can select Edit ➪
Indent Code or use the keyboard shortcut Ctrl+> (Command+>) to indent a code block, and
Edit ➪ Outdent Code or the keyboard shortcut Ctrl+< (Command+<) to outdent it.
As a further aid to help you find your way through a maze of code, Dreamweaver includes the
Balance Braces command. JavaScript is notorious for using parentheses, brackets, and curly
braces to structure its code—and it’s easy to lose sight of where one enclosing brace begins
and its closing mate ends. Dreamweaver highlights the content found within the closest pair
of braces to the cursor when you select Edit ➪ Balance Braces or use the keyboard shortcut
Ctrl+’ (Command+’). If you select the command again, the selection expands to the set of
surrounding braces. When the selection is not enclosed by parentheses, brackets, or curly
braces, Dreamweaver sounds an alert.
Although most Web designers prone to using the code editor in Dreamweaver prefer to
manually enter their code, the power of the Insert bar is still at your disposal for rapid code
development. Any element available from the Insert bar can be inserted directly into Code
view or the inspector. To use the Insert bar, you must first position your cursor where you
would like the code for the object to appear. Then select the element or drag and drop the
element from the Insert bar to Code view or the inspector.
Keep in mind that Dreamweaver’s code editor is highly customizable. You can change the
way the lines wrap, by using indents for certain tag pairs; you can even control the amount
of indentation. All the options are outlined for you in Chapter 4.
Printing code
Although you may spend the vast majority of your time writing, modifying, and debugging
your code onscreen, there are times when you need to see it in hard copy.
Dreamweaver now offers the option of printing out your code. Choose File ➪ Print Code to
open the standard operating system Print dialog box. You have the option to print all of the
code or a selection; you cannot, however, print individual pages of your code. Press the keyboard
shortcut, Ctrl+P (Command+P) to send your code directly to the printer. Although
Dreamweaver does not print the syntax coloring, you can print line numbers just by enabling
them in Code view options.

4. Establishing page properties


When you first start Dreamweaver, your default Web page is untitled, with no background
image, and only a plain, white background. You can change any of these properties and more
through Dreamweaver’s Page Properties dialog box.
Attributes entered through the Page Properties dialog box are written into the <body> tag.
An increasing number of Web designers prefer to control these attributes through a
Cascading Style Sheet (CSS). For more information on CSS, see Chapter 20.
You can also change the document title in Dreamweaver’s Document toolbar. Just enter the
information in the Title field and press Enter (Return) to confirm the modification. You’ll see
the new title appear in the program’s title bar and whenever you preview the page in a
browser.
As usual, Dreamweaver gives you more than one method for accessing the Page Properties
dialog box. You can select Modify ➪ Page Properties, or you can use the keyboard shortcut
Ctrl+J (Command+J).
Here’s another way to open the Page Properties dialog box: Right-click (Control+click) any
open area in the Document window—that is, any part of the screen not occupied by an
image, table, or other object (text outside of tables is okay to click, however). From the
bottom of the context menu, select Page Properties.


Understanding <meta> and other <head> tags
Summary information about the content of a page—and a lot more—is conveyed through
<meta> tags used within the <head> section. The <meta> tag can be read by the server to
create a header file, which makes it easier for indexing software used by search engines to
catalog sites. Numerous different types of <meta> tags exist, and you can insert them in your
document just like other objects.
One <meta> tag is included by default in every Dreamweaver page. The Document Encoding
option of the Page Properties dialog box determines the character set used by the current
Web page and is displayed in the <head> section as follows:
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1”>
The preceding <meta> tag tells the browser that this page is, in fact, an HTML page and that the
page should be rendered using the specified character set (the charset attribute). The key
attribute here is http-equiv, which is responsible for generating a server response header.
Once you’ve determined your <meta> tags for a Web site, the same basic <meta> information
can go on every Web page. Dreamweaver gives you a way to avoid having to insert the
same lines repeatedly: templates. Once you’ve set up the <head> elements the way you’d
like them, choose File ➪ Save As Template. If you want to add <meta> or any other <head>
tags to an existing template, you can edit the template and then update the affected pages.
For more information about templates, turn to Chapter 28.
In Dreamweaver, you can insert a <meta> tag or any other tag using the <head> tag objects,
which you access via the Head category in the Insert bar or the Insert ➪ Head Tags menu
option. The <head> tag objects are described in Table 6-1 and subsequent subsections.
Table 6-1: Head Tag Objects
Object Description
Meta Inserts information that describes or affects the entire document
Keywords Includes a series of words used by some search engines to index the current Web
page and/or site
Description Includes a text description of the current Web page and/or site
Refresh Reloads the current document or loads a new URL within a specified number of
seconds
Base Establishes a reference for all other URLs in the current Web page
Link Inserts a link to an external document, such as a style sheet
Cross-
Reference
Cross-
Reference
226 Part II ✦ Web Design and Layout
Inserting tags with the Meta object
The Meta object is used to insert tags that provide information for the Web server, through
the HTTP-equiv attribute, and other overall data that you want to include in your Web page
but not make visible to the casual browser. Some Web pages, for example, have built-in expiration
dates after which the content is to be considered outmoded. In Dreamweaver, you can
use the Meta object to insert a wide range of descriptive data.
You can access the Meta object in the Head category of the Insert bar or via the Insert menu
by choosing Insert ➪ Head Tags ➪ Meta. Like all the Head objects, you don’t have to have the
Head Content visible to insert the Meta object; although you do have to choose View ➪ Head
Content if you wish to edit the object. To insert a Meta object, follow these steps:
1. Select Insert ➪ Head Tags ➪ Meta or select the Meta object from the Head category of
the Insert bar. Your current cursor position is irrelevant.
The Meta dialog box opens, as shown in Figure 6-3.
Figure 6-3: The Meta object enables you to enter a full range of <meta> tags in the
<head> section of your Web page.
Meta dialog box
Meta icon
Chapter 6 ✦ Accessing the Code Directly 227
2. Choose the desired attribute: Name or an HTTP equivalent from the Attribute list box.
Press Tab.
3. Enter the value for the selected attribute in the Value text box. Press Tab.
4. Enter the value for the content attribute in the Content text box.
5. Click OK when you’re done.
You can add as many Meta objects as you need to by repeating Steps 1 through 4. To edit an
existing Meta object, you must first choose View ➪ Head Content to reveal the <head> code,
indicated by the various icons. Select the Meta icon and make your changes in the Property
inspector.
Aiding search engines with the Keywords and Description objects
Let’s take a closer look at the tags that convey indexing and descriptive information to some
search engine spiders. These chores are handled by the Keywords and Description objects.
As noted in the sidebar, “Built-in Meta Commands,” the Keywords and Description objects
output specialized <meta> tags.
Both objects are straightforward to use. Choose Insert ➪ Head Tags ➪ Keywords or Insert ➪
Head Tags ➪ Description. You can also choose the corresponding objects from the Head category
of the Insert bar. Once selected, these objects open similar dialog boxes with a single
entry area, a large text box, as shown in Figure 6-4. Enter the values—whether keywords or a
description—in the text box and click OK when you’re done. You can edit the Keywords and
Description objects, like the Meta object, by selecting their icons in the Head area of the
Document window, revealed by choosing View ➪ Head Contents.
Although you can enter paragraph returns in your Keywords and Description objects, there’s
no reason to. Browsers ignore all such formatting when processing your code.


Built-in Meta Commands
Although Dreamweaver presents six different Head objects, <meta> tags form the basis of four of
them: Meta, Keywords, Description, and Refresh. By specifying different name attributes, the purpose
of the <meta> tags changes. For example, a Keywords object uses the following format:
<meta name=”keywords” content=”dreamweaver, web, authoring, Æ
HTML, DHTML, CSS, Macromedia”>
whereas a Description object inserts this type of code:
<meta name=”description” content=”This site is devoted to Æ
extensions made possible by Macromedia’s Dreamweaver, the Æ
premier Web authoring tool.”>
It is possible to create all your <meta> tags with the Meta object by specifying the name attribute
and giving it the pertinent value, but it’s easier to just use the standard Dreamweaver Head
objects.
228 Part II ✦ Web Design and Layout
Figure 6-4: Entering information through the Keywords object helps search engines
correctly index your Web page.
What you place in the Keywords and Description objects can have a big impact on your Web
page’s accessibility. If, for example, you want to categorize your Web page as an homage to
the music of the early seventies, you could enter the following in the Content area of the
Keywords object:
music, 70s, 70’s, eagles, ronstadt, bee gees, pop, rock
In the preceding case, the content list is composed of words or phrases, separated by commas.
Use sentences in the Description object, as follows:
The definitive look back to the power pop rock stylings of early 1970s
music, with special sections devoted to the Eagles, Linda Ronstadt, and
the Bee Gees.
Keep in mind that the content in the Description should complement and extend both the
Keywords and the Web page title. You have more room in both the Description and Keywords
objects—actually, an unlimited amount—than in the page title, which should be on the
short side in order to fit into the browser’s title bar.

When using <meta> tags with the Keywords or Description objects, don’t stuff the <meta>
tags repeatedly with the same word. The search engines are engineered to reject multiple
instances of the same words, and your description will not get the attention it deserves.
Refreshing the page and redirecting users
The Refresh object forces a browser to reload the current page or to load a new page after a
user-set interval. The Web page visitor usually controls refreshing a page; if, for some reason,
the display has become garbled, the user can choose Reload or Refresh from the menu to
redraw the screen. Impatient Web surfer that I am, I often stop a page from loading to see
what text links are available and then—if I don’t see what I need—hit Reload to bring in the
full page. The code inserted by the Refresh object tells the server, not the browser, to reload
the page. This can be a powerful tool but leads to trouble if used improperly.
To insert a Refresh object, follow these steps:

1. Choose Insert ➪ Head Tags ➪ Refresh or select the Insert Refresh object from the Head
category of the Insert bar.
The Refresh dialog box, shown in Figure 6-5, opens.
Figure 6-5: Use the Refresh object to redirect visitors from an outdated page.
Refresh dialog box
Refresh icon
Caution
230 Part II ✦ Web Design and Layout
2. Enter the number of seconds you want to wait before the Refresh command takes effect
in the Delay text box.
The Delay value is calculated from the time the page finishes loading.
3. Select the desired Action:
• Go to URL
• Refresh This Document
4. If you selected Go to URL, enter a path to another page in the text box or select the
Browse button to select a file.
5. Click OK when you’re done.
The Refresh object is most often used to redirect a visitor to another Web page. The Web is a
fluid place, and sites often move from one address to another. Typically, a page at the old
address contains the Refresh code that automatically takes the user to the new address. It’s
good practice to include a link to your new URL on the “change-of-address” page because not
all browsers support the Refresh option. One other tip: Keep the number of seconds to a
minimum—there’s no point in waiting for something to happen automatically when you
could click a link.
If you elect to choose the Refresh This Document option, use extreme caution, for several
reasons. First, you can easily set up an endless loop for your visitors in which the same page
is constantly being refreshed. If you are working with a page that updates often, enter a
longer Refresh value, such as 300 or 500. You should be sure to include a link to another
page to enable users to exit from the continually refreshed page. You should also be aware
that many search engines will not index pages using the <meta> refresh tag because of
widespread abuse by certain industries on the Web.

Changing bases
Through the Base object, the <head> section enables you to exert fundamental control over
the basic HTML element: the link. The code inserted by this object specifies the base URL for
the current page. If you use relative addressing (covered in Chapter 9), you can switch all
your links to another directory—even another Web site—with one command. The Base
object takes two attributes: Href, which redirects all the other relative links on your page;
and target, which specifies where the links will be rendered.
To insert a Base object in your page, follow these steps:

1. Choose Insert ➪ Head Tags ➪ Refresh or select the Base object from the Head category
of the Insert bar.
The Base dialog box opens.
2. Input the path that you want all other relative links to be based on in the Href text box
or choose the Browse button to pick the path.
3. If desired, enter a default target for all links without a specific target to be rendered in
the Target text box.
4. Click OK when you’re done.
Caution
Chapter 6 ✦ Accessing the Code Directly 231
How does a <base> tag affect your page? Suppose you define one link as follows:
images/backgnd.gif
Normally, the browser looks in the same folder as the current page for a subfolder named
images. A different sequence occurs, however, if you set the <base> tag to another URL in
the following way:
<base href=”http://www.testsite.com/client-demo01/”>
With this <base> tag, when the same images/backgnd.gif link is activated, the browser
looks for its file in the following location:
http://www.testsite.com/client-demo01/images/backgnd.gif
Because of the all-or-nothing capability of <base> tags, many Webmasters use them
cautiously, if at all.
Linking to other files
The Link object indicates a relationship between the current page and another page or file.
Although many other intended uses exist, the <link> tag is most commonly used to apply an
external Cascading Style Sheet (CSS) to the current page. This code is entered automatically
in Dreamweaver when you create a new linked style sheet (as described in Chapter 20), or
you can add the attributes yourself with the Link object. The <link> tag is also used to
include TrueDoc dynamic fonts.
One other popular use of the <link> tag is to create favicons. A favicon is a small icon that
appears in the Favorites menu of Internet Explorer browsers when you mark a site as a
Favorite or bookmarked. To have a favicon appear when a page is bookmarked, create a favicon
using one of the tools listed at www.favicon.com and upload that image file to your
site. Then put a tag like this on your page:
<LINK REL=”SHORTCUT ICON” HREF=”/images/fav.ico”>.
where fav.ico is the name of the icon file, here stored in the images folder at the root of the site.
To insert a Link object, first choose Insert ➪ Head Tags ➪ Link or select the Insert Link object
from the Head category of the Insert bar. This action opens the Link dialog box.


Attribute Description
Href The path to the file being linked. Use the Browse button to open the Select File
dialog box.
ID The ID attribute can be used by scripts to identify this particular object and affect
it if need be.
Title The Title attribute is displayed as a ToolTip by Internet Explorer browsers.
Rel A keyword that describes the relationship of the linked document to the current
page. For example, an external style sheet uses the keyword stylesheet.
Rev Rev, like Rel, also describes a relationship but in the reverse. For example, if
home.html contained a link tag with a Rel attribute set to intro.html, intro.html
could contain a link tag with a Rev attribute set to home.html.
Aside from the style sheet use, there’s little browser support for the other link functions.
However, the World Wide Web Consortium (W3C) supports an initiative to use the <link>
tag to address other media, such as speech synthesis and Braille devices, and it’s entirely
possible that the Link object will be used for this purpose in the future.
Adding to the <body>
The content of a Web page—the text, images, links, and plugins—is all contained in the
<body> section of an HTML document. The great majority of <body> tags can be inserted
through Dreamweaver’s visual layout interface.
To use the <body> tags efficiently, you need to understand the distinction between logical
styles and physical styles used in HTML. An underlying philosophy of HTML is to keep the
Web as universally accessible as possible. Web content is intended to be platform- and
resolution-independent, but the content itself can be styled by its intent as well. This
philosophy is supported by the existence of logical <body> tags (such as <code> and
<cite>), with which a block of text can be rendered according to its meaning, and physical
style tags for directly italicizing or underlining text. HTML enables you to choose between
logical styles, which are relative to the text, or physical styles, which can be regarded as
absolute.

Saturday, January 26, 2013

3. Expanding into XHTML


The latest version of HTML is known as XHTML, short for eXtensible HTML. XHTML is based on
XML and, as such, has a more rigid syntax than HTML. For example, tags that do not enclose
content—the so-called empty tags—are written differently. In HTML, a line-break tag is
<br>
whereas in XHTML, the line-break tag is
<br />
Note the additional space and the closing slash. Other differences include an opening XML
declaration as well as a specific doctype tag placed before the opening <html> tag. All tags
must be in lowercase, and all attribute values must appear in quotes, (but not necessarily
lowercase) as follows:
<table align=”RIGHT”>
Dreamweaver makes it easy to code in XHTML, and even to convert existing pages from
HTML to XHTML. To work in XHTML from the ground up, select the Make Document XHTML
Compliant option on the New Document category of Preferences (available when you choose
Edit ➪ Preferences). Selecting this option will automatically select an identical option on the
New Document dialog box (File ➪ New)—which, if necessary, you can disable on a case-bycase
basis. Once a document has been set as an XHTML file, all the tags are written in the
proper style.
To switch an HTML page to an XHTML one, choose File ➪ Convert ➪ XHTML. The conversion
is automatically applied to the current document; there is no standard method to convert an
entire site.
Since Dreamweaver has taken the pain out of using XHTML, the question is, should you code
in XHTML or HTML? As in most situations, it depends. Many larger companies that work
extensively in XML require well-formed XHTML pages. As the latest version of the Web’s core
language—and recommended by the W3C—you’ll be perfectly poised for the future. One
aspect of the future is the proliferation of Internet devices other than the computer: PDAs,
cell phones, and set-top boxes, among others. XHTML is far more portable to these types of
devices than HTML.


doctype and doctype Switching

The very first element of an HTML page—even before the <html> tag—is, increasingly, a
doctype declaration. As the name implies, a doctype declaration specifies the language or,
more specifically, the DTD (Document Type Definition) in use for the file that follows. To
validate their page, many authors include doctype statements like the following:
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
This doctype is inserted by default when Dreamweaver creates a new static HTML page.
The latest—in fact, the last—version of HTML recommended by the W3C is version 4.01.
After this version, the W3C recommended the switch to XHTML.
Recent browser versions have begun inspecting the doctype element in order to determine
how the page should be rendered. Engaging in a practice known as doctype switching, these
browsers (Internet Explorer 5 on the Macintosh, Internet Explorer 6, and Netscape 6) work in
two modes: strict and regular. When in strict mode, a page must be well-formed and validate
without error to be rendered properly. Strict rendering is more consistent across browsers.
The regular mode is far looser and more forgiving in how the page is coded; however, your
page is more likely to be rendered differently in the varying browser versions.
You can ensure that your pages are rendered in the regular mode in a number of ways:
✦ Do not include a doctype declaration at all.
✦ Use a doctype declaration that specifies an HTML version earlier than 4.0.
✦ Use a doctype declaration that declares a transitional DTD of HTML 4.01, but does not
include a URL to the DTD.
To trigger a browser’s strict rendering mode:
✦ Use a doctype declaration for XML or XHTML.
✦ Use a doctype declaration that declares a strict DTD of HTML 4.01.
✦ Use a doctype declaration that declares a transitional DTD of HTML 4.01 that includes a
URL to the DTD.
When including a URL to the DTD, the doctype looks as follows:
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
“http://www.w3.org/TR/html4/loose.dtd”>
You have several alternatives in Dreamweaver for including whichever doctype you choose.
Hand-coding is a sure but tedious method; the doctype statement is somewhat cumbersome
and certainly not easy to remember precisely. You could also alter the standard HTML page by
changing the Default.html file found in your Configuration\DocumentTypes\NewDocuments
folder.
Note

2. Web Design and Layout.


Accessing the Code Directly


As far as most designers are concerned, in a perfect world, you
could lay out a complex Web site with a visual authoring tool
and never have to see the HTML and other code, much less modify it.
Dreamweaver takes you a long way toward this goal—in fact, you
can create many types of Web pages using only Dreamweaver’s
Design view. As your pages become more complex, however, you will
probably need to tweak your code in one way or another.
Programmers, on the other hand, are happiest working directly with
the code. To accomplish their goals efficiently, coders need a responsive,
flexible editor capable of handling a wide range of computer
languages. Just how much assistance is required is a matter of personal
taste: Some code writers want all the help they can get, with
features such as syntax coloring, code completion, and Code Hints,
among others, whereas other programmers just want their editor to
stay out of their way.
Dreamweaver tries to give coders the best of both worlds by providing
a full-featured editor with numerous options. In addition to the features
mentioned in the preceding paragraph, Dreamweaver includes
full tag libraries in numerous languages: HTML, CFML, ASP.NET, JSP,
and PHP, to name a few. Both hand-coders and visual designers can
enjoy the benefits of Dreamweaver tools such as the Snippets panel,
for adding chunks of code via drag-and-drop, and the Tag Inspector,
for displaying all the attributes of a chosen tag—and making them
editable as well. This chapter covers all of these features and more.
While the Internet is made up of a plethora of technologies, HTML is
still at the heart of a Web page. This chapter gives you a basic understanding
of how HTML works and provides you with the specific
building blocks you need to begin creating Web pages. This chapter
also gives you your first look at a Dreamweaver innovation: Code
view, for altering the code side-by-side with the visual environment.
The other Dreamweaver-specific material in this chapter—which
primarily describes how Dreamweaver sets and modifies a page’s
properties—is suitable for even the most accomplished Web designers.
Armed with these fundamentals, you are ready to begin your
exploration of Web page creation.

The Structure of a Web Page


The simplest explanation of how HTML works derives from the full expansion of its acronym:
Hypertext Markup Language. Hypertext refers to one of the World Wide Web’s main properties—
the capability to jump from one page to another, no matter where the pages are located on the
Web. Markup Language means that a Web page is actually a heavily annotated text file. The basic
building blocks of HTML, such as <strong> and <p>, are known as markup elements, or tags. The
terms element and tag are used interchangeably.
An HTML page, then, is a set of instructions (the tags) suggesting to your browser how to
display the enclosed text and images. The browser knows what kind of page it is handling based
on the tag that opens the page, <html>, and the tag that closes the page, </html>. The great
majority of HTML tags come in such pairs, in which the closing tag always has a forward slash
before the keyword. Two examples of tag pairs are: <p>. . .</p> and <title>. . .</title>.
A few important tags are represented by a single element: the image tag <img>, for example.
The HTML page is divided into two primary sections: the <head> and the <body>. Information
relating to the entire document goes in the <head> section: the title, description, keywords,
and any language subroutines that may be called from within the <body>. The content of the
Web page is found in the <body> section. All the text, graphics, embedded animations, Java
applets, and other elements of the page are found between the opening <body> and the
closing </body> tags.
When you start a new document in Dreamweaver, the basic format is already laid out for you.


Listing 6-1: The HTML for a New Dreamweaver Page
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1”>
</head>
<body>
</body>
</html>
We’ll cover the opening <!DOCTYPE> tag a little later in this chapter in “Doctype and Doctype
Switching”. First you should notice how the <head>. . .</head> pair is separate from the
<body>. . .</body> pair, and that both are contained within the <html>. . .</html>
tags.
Note also that the <meta> tag has two additional elements:
http-equiv=”Content-Type”
and
content=”text/html; charset=iso-8859-1”



1. Basic with Dreamweaver.


Dreamweaver MX Basics:

Dreamweaver MX, by Macromedia, is a professional Web site development program for creating static pages and dynamic Web applications. Among its many distinctions, Dreamweaver was the first Web authoring tool capable of addressing multiple server models, making it equally easy for developers of ASP, ColdFusion, or JavaServer Pages to use. In its latest incarnation, Dreamweaver MX has re-invented itself with a new user interface and a broader focus; in addition to creating straight HTML pages, Dreamweaver is also suitable for coding a wide range of Web formats including JavaScript, XML, and ActionScript to name a few. Dreamweaver is truly a tool designed by Web developers for Web developers. Designed from the ground up to work the way professional Web designers do, Dreamweaver speeds site construction and streamlines site maintenance. This chapter describes the philosophical underpinnings of the program and provides a sense of how Dreamweaver blends traditional HTML and other Web languages with cutting-edge server-side techniques. You also learn some of the advanced features that Dreamweaver offers to help you manage a Web site.

The Dynamic World of Dreamweaver:


Dreamweaver is a program very much rooted in the real world. Web
applications are developed for a variety of different server models, and
Dreamweaver writes code for the most pervasive ones. The real world
is also a changing world, and Dreamweaver’s extensible architecture
opens the door for custom or third-party server models as well.
Moreover, Dreamweaver recognizes the real-world problem of incompatible
browser commands and addresses the problem by producing
code that is compatible across browsers. Dreamweaver includes
browser-specific HTML validation so you can see how your existing
or new code works in a particular browser.
Dreamweaver MX extends the real-world concept to the workplace.
Features such as the Assets panel streamline the production and
maintenance process on large Web sites. The advanced Design view
makes it possible to quickly structure whole pages during the production
stage, while maintaining backward compatibility with

Connecting to the world’s data:


Connectivity is more than a buzzword in Dreamweaver; it’s an underlying concept. Dreamweaver
makes it possible to connect to any data source supported by the most widely used application
servers: ASP, ASP.NET, ColdFusion, PHP, and JSP. Moreover, the actual connection type is quite
flexible; developers may opt for a connection that is easier to implement but less robust or one
that requires slightly more server-side savvy and offers greater scalability. Dreamweaver even
offers a choice of languages for a number of applications servers, as shown in Figure 1-1.
Figure 1-1: Get a jump start on building your Web pages by choosing a page—and the
corresponding tags—from Dreamweaver’s extensive collection.

Dreamweaver accesses standard recordsets—a subset of a database—as well as more
sophisticated data sources, such as session or application variables and stored procedures.
Through their implementation of cookies and server-side code, Web applications designed in
Dreamweaver may track visitors or deny them entrance.
You’ll also find support in Dreamweaver for high-end technologies such as Web services,
JavaBeans, and ColdFusion components. Dreamweaver allows you to introspect elements of
all technologies, enabling coders to quick grasp the syntax, methods, and functions required.


Choice of environments:

For the first time, Dreamweaver MX offers developers a choice of design environments. The
classic floating panel interface is available for both Windows and Macintosh users, and
Windows users have the option of selecting an integrated workspace.
The new integrated workspace, available for Windows users, utilizes a Multiple Document
Interface (MDI) that keeps all the open documents and panels together in one application
window. There are two flavors of the MDI workspace: the default with panels grouped on the
right and HomeSite style, with panels on the left. As shown in Figure 1-5, you switch from
one workspace to another in Preferences.



Easy text entry
Although much of the World Wide Web’s glitz comes from multimedia elements such as
images and sound, Web pages are primarily a text-based medium. Dreamweaver recognizes
this and makes the text cursor the default tool. To add text, just click in Dreamweaver’s main
workspace—the Document window—and start typing. As shown in Figure 1-6, the Text
Property inspector even enables you to change characteristics of the text, such as the size,
font, position, or color by assigning a Cascading Style Sheet (CSS) style; you can also use
regular HTML tags if you prefer.

Drag-and-drop data fields
It’s one thing to make a connection to a data source; it’s quite another to actually insert the
dynamic data in the proper place on the Web page. Dreamweaver makes drag-and-drop easy
with the Bindings panel. All the available data sources for a page are displayed in an expandable
tree outline in the Bindings panel, as shown in Figure 1-7. An instance of any dynamic
field displayed in the panel may be inserted on the page by either dropping it into place or by
using the Insert button.