Working with a Web Page in Code View
So far you've learned how to build web pages in Design view. The Design view, supported by the design window, Properties Inspector, Insert bar, and supporting panels make Dreamweaver an attractive editor for visual developers hoping to create quick web pages without having to know markup or the sometimes confusing coding languages such as CSS and JavaScript. Although working in Design view may certainly be a positive for most developers, it's important to highlight some of the supported coding features that truly make Dreamweaver one of a kind. The last part of this chapter hopes to unleash the unique coding aspects that some people come to expect from the industry-leading web-page-development environment.
Code Hints
We've looked at some of the visual preferences (such as line numbers, word wrap, and syntax coloring) in Code view, we've yet to outline and detail some of the powerful features that can aid you in development regardless of view. Arguably one of the most useful features in Code view is that of code hints. Those who made a living developing with HomeSite in the late 1990s certainly remember this feature because it was integral part of the HomeSite development environment and a huge reason HomeSite's popularity was unmatched. Thanks to the Macromedia/Allaire merger, Dreamweaver gained from the popularity that code hints had in HomeSite. Using code hints in the Code view environment is easy; understanding how it works is to understand the underlying structure behin214/XHTML. HTML/XHTML is an authoring language, not a programming language. The developer is entirely responsible for creating the structure that she wants her users to see using a markup language lik215/XHTML. Organized using a well-formed structure of tags in conjunction with attributes, the browser parses the tags and presents to the user the structure that the developer intended. For future reference,
Figure 3.51. HTML tags contain attributes, attribute values, and generally wrap literal text or in some cases, othe228 elements such as images.

[View full size image]

Figure 3.53. All attributes for a selected tag appear in the code hints menu.
The Code View Toolbar
For developers used to working with code in HomeSite, the Code View toolbar docked to the left side of the coding environment and shown in Figure 3.54 should look relatively familiar.
Figure 3.54. The Code View toolbar provides quick access to commonly used commands for the Code view user.
[View full size image]

- Open Documents :
Click and hold this icon in the toolbar to display all currently open documents. Then choose a document from the list to focus the document in Code view. - Collapse Full Tag :
You can place your cursor onto an opening tag and then click this button to collapse the tag and everything within it. This button is discussed in more detail in the next section. - Collapse Selection :
You can highlight a section of code and then click this button to collapse the selection. This button is discussed in more detail in the next section. - Expand All :
Expands all collapsed code. - Select Parent Tag :
Selects the parent tag within the hierarchy based on your cursor position in the code. For example, if you're within the <td> tag of a table, selecting this option selects the <table> tag because the <table> tag is the parent for both the <tr> and <td> tags. - Balance Braces :
When working with client-side scripting languages such as JavaScript, click this button to highlight all code within the braces of a function. - Line Numbers :
Displays or hides line numbers. - Highlight Invalid Code :
Similar to the Highlight Invalid Code option (located in the View options menu in the Document bar), choose this option to enable or disable the highlighting of code that is considered invalid to a browser. - Apply/Remove Comment :
Choose the Apply Comment button to open the comment selection menu similar toFigure 3.55. Choose a comment type from the comment selection menu.
[View full size image] - Wrap Tag :
Highlighting an element in code and selecting this button opens the Wrap Tag dialog. It from this dialog that you can enter an element that should wrap the selection. You'll notice that code hints also work within the Wrap Tag dialog. - Recent Snippets :
Selecting this button opens the recent snippets menu. From this menu, you can pick from a list of recently added snippets or even launch the Snippets panel to choose from Dreamweaver's library of snippets. - Indent/Outdent Code :
Choose from these two buttons to indent or outdent code. - Format Source Code :
Also available from the Commands menu, you can click and hold this option to apply the default Dreamweaver code formatting to either the entire page of code or to selected blocks of code. Alternatively, you can choose the Code Format Settings option to launch the Preferences dialog with the Code Format option preselected. More information about Preferences is provided in Chapter 5, "Defining Preferences."
Of course, you can also show and hide the Code View toolbar by right-clicking the toolbar and checking/unchecking the Coding option from the context menu.
Code Collapse
Code collapsing provides the developer with the ability to highlight a segment of code and collapse it so that it's temporarily hidden from view. The obvious benefit to this is increased screen real-estate. To use the code collapse feature, follow these steps:
1. | With the companydirectory page open, switch to Code view if it's not already selected. |
2. | Highlight a section of code. Notice the line segments that appear in the line numbers column similar to Figure 3.56.Figure 3.56. Line segments appear in the line numbers column, indicating the segment of code that can be collapsed.[View full size image] ![]() |
3. | Choose one of the segment icons to collapse the code similar to Figure 3.57. Alternatively, you can choose the Collapse Selection button from the Code View toolbar. Notice the small plus (+) icon that appears next to the collapsed code.Figure 3.57. The code is collapsed and temporarily hidden from view.[View full size image] ![]() |
4. | You can expand the code by choosing the plus (+) icon that appears next to the collapsed code. Alternatively, choose the Expand All button in the Code View toolbar to expand all collapsed code. |
The Tag Inspector
After you've created the tag structure, you can use the Tag Inspector to format all attributes of a tag through a visual panel. Part of the Tag panel group and available by choosing Tag Inspector from the Window menu, the Tag Inspector visually categorizes and lists all attributes supported by a tag. As you can see in Figure 3.58, the Tag Inspector displays all attributes and attribute values for the selected tag.
Figure 3.58. The Tag Inspector visually displays attributes and attribute values for a selected tag.

Figure 3.59. Enter attribute values or select from a list of attribute values in some cases.

Using the Tag Chooser
The next major addition to the development interface is the Tag Chooser. The Tag Chooser, available by selecting the Tag option from the Insert menu, is a collection o216, CFML, ASP.NET, JSP, JRun, ASP, PHP, WML, and XSLT tags. To use this intuitive window, place your cursor in the <body> tag and choose Tag from the Insert menu. The Tag Chooser dialog appears similar to

Figure 3.61. HTML tags are organized in categories. Selecting a tag opens the reference for the tag in the More Info pane.

Figure 3.62. The Tag Editor dialog allows you to format properties for a specific tag.
[View full size image]

Working with Snippets
The final development aid you can use in the Code view is snippets. Snippets are a clever way to save small blocks of prewritten code so that they are always available to you (and other developers) for use. Available from the Code panel group, the Snippets panel is structured as a series of folders into which snippets are organized. Each folder covers a particular technology or area of functionality. As you can see from Figure 3.63, Dreamweaver includes numerous code snippets you can use.
Figure 3.63. Code snippets are organized into folders specific to the respective technology. Dreamweaver includes prebuilt snippets you can use.

1. | Create a new folder for your snippet by right-clicking in the Snippets window and choosing New Folder. Give the snippet folder a descriptive name, remembering that other developers might want to use these snippets, too. If the folder is created in the "wrong" place, you can drag it to the level you want. I'll call my new folder Table Row Rollover . |
2. | Right-click the folder and choose New Snippet from the context menu. If you have already written the snippet code in the page, highlight the code you want to use as the snippet, right-click the highlighted code, and choose Create New Snippet from the context menu. |
3. | You are presented with the Snippet dialog. Fill in the snippet name and description. If you have highlighted existing code, the code box is already filled in. I'll add the followin217 code to the Insert Before text box:This code effectively creates a new table, complete with rows; when the user's mouse rolls over the rows, the background color changes to a gray color. |
4. | If you want the code to flow around a selected object, such as an image or table cell, select the Wrap Selection option, specifying which part of the code goes before the object and which after the object. If the code is a standalone block, choose the Insert Block option. I'll choose Insert Block. The completed Snippet dialog should resemble Figure 3.64.Figure 3.64. Create the new snippet in the Snippet dialog.To use the snippet, simply drag the snippet into the code environment and choose Preview In Browser (or press F12) to test the results.Editing, moving, and deleting snippets are also a snap. To edit a snippet, right-click the snippet and choose Edit from the context menu. The Snippet dialog appears, and you can edit the code or change the description. To move snippets into other folders, drag them to the folder you want. To delete a snippet or its respective folder, right-click the snippet (or folder) and press the Delete key. |