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.
No comments:
Post a Comment