- Creating a New Document
- Working with a New Document in Design View
- Inserting the Time and Date
- Inserting a Horizontal Rule
- Working with Images
- Working with Hyperlinks
- Working with a Web Page in Code View
- Summary
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 behind HTML/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 like HTML/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 outlines the structure of a typical HTML/XHTML tag.
Figure 3.51 HTML tags contain attributes, attribute values, and generally wrap literal text or in some cases, other HTML elements such as images.
The more intricate the structure and inclusion of tags and attributes, the more detailed the design can look within the browser. As an HTML/XHTML developer, you’ll quickly realize that there are hundreds of HTML/XHTML tags, with each tag having dozens of attribute combinations. As a developer, it’s extremely difficult to remember them all. Fortunately, Dreamweaver’s code hints automate what we may want to add. Accessing code hints is as simple as switching to Code view in a new HTML page, placing your cursor in the <body> tag, and typing. For instance, if I type the < symbol (this symbol represents the beginning of an HTML tag), the code hints menu appears complete with every supported HTML tag (see Figure 3.52).
I can use the keyboard up and down arrow keys to cycle through the tags in the code hints menu. When I’ve found the tag I want to use, I press Enter to add it to the code. Pressing the spacebar opens the code hints menu again, but this time only the attributes for the selected tag appear (see Figure 3.53). (You could also just continue typing, and Dreamweaver auto searches and updates the code hints menu with the most appropriate tag based the letters you have entered.) When your tag is highlighted, press Enter.
Figure 3.52 The code hints menu appears complete with all possible HTML tags.
Figure 3.53 All attributes for a selected tag appear in the code hints menu.
Again, pressing Enter adds the selected attribute. Depending on the attribute you add, the code hints becomes more detailed. In my case, I choose the href attribute (creates the reference for the hyperlink) of the <a> (tag used for creating links) tag. The Browse code hint then appeared, allowing me to choose a file. After I add my file, I can use the right-arrow key to move to the next attribute and press the spacebar to repeat the process. When I finish formatting the tag, I need only add the > symbol to close out the opening tag. Finally, I’ll add the < symbol to begin the closing tag followed by the / symbol, in which case the closing tag is added automatically for me by Dreamweaver.
As I mentioned earlier, the more intricate the structure of your HTML/XHTML, the better your designs will look...the possibilities are limited only by your needs.
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.54should look relatively familiar.
Figure 3.54 The Code View toolbar provides quick access to commonly used commands for the Code view user.
The Code View toolbar provides quick access to commonly used commands for the Code view user, specifically:
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 to Figure 3.55. It’s from this menu that you have the option of inserting a HTML, CSS, JavaScript, or VB.NET, comment. Alternatively, you can click the Remove Comment button to delete an existing comment from the code view.
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."
Figure 3.55 Choose a comment type from the comment selection menu.
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:
With the companydirectory.htm page open, switch to Code view if it’s not already selected.
Highlight a section of code. Notice the line segments that appear in the line numbers column similar to Figure 3.56.
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.
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.
Figure 3.56 Line segments appear in the line numbers column, indicating the segment of code that can be collapsed.
Figure 3.57 The code is collapsed and temporarily hidden from view.
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.
Depending on the attribute value you select, the Tag Inspector either allows you to manually type a value or allows you to select from a list of values through a menu similar to Figure 3.59.
Figure 3.59 Enter attribute values or select from a list of attribute values in some cases.
Although the Tag Inspector works in both Code and Design views, its inclusion and subsequent benefits are immediately obvious.
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 of HTML, 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.60.
Figure 3.60 The Tag Chooser contains a complete collection of HTML, CFML, ASP.NET, JSP, JRun, ASP, PHP, and WML tags.
Choose the tag collection you’d like to explore; the tags are further organized within structural categories. For instance, the <a> tag is organized in the General option of the Page Elements category. Choosing the <a> tag from the elements pane also reveals the HTML reference for the <a> tag within the More Info pane similar to Figure 3.61.
Figure 3.61 HTML tags are organized in categories. Selecting a tag opens the reference for the tag in the More Info pane.
To insert a selected tag, simply choose the tag and click Insert to launch the Tag Editor dialog (see Figure 3.62).
Figure 3.62 The Tag Editor dialog allows you to format properties for a specific tag.
After you’ve formatted the attributes of the tag, click OK to insert the tag into the coding environment. You can either continue adding tags using the Tag Chooser or click Close to return to the coding environment.
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.
Notice that the Snippets panel is organized into two halves. The top half includes a preview of the code snippet selected from the categorized list of snippets in the bottom half. HTML snippets are usually shown in Design view (showing what the HTML looks like in the browser), whereas JavaScript and other code snippets are shown in Code view (so that you can see the actual code). Inserting a snippet is merely a matter of selecting the appropriate snippet and either dragging it into the code environment or clicking the Insert button located in the bottom left of the Snippets panel.
Creating your own snippet is just as easy but slightly more involved. To create your own snippet, follow these steps:
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.
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.
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 following HTML 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.
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.
When you finish editing the Snippet dialog, click OK. The new snippet appears in its folder and the preview pane will display the HTML.
<table> <tr onmouseover="this.style.backgroundColor=’#cccccc’;" onmouseout="this.style.backgroundColor=’#ffffff’;"> <td align="center" width="125"><a href="#">Home</a></td> </tr> <tr onmouseover="this.style.backgroundColor=’#cccccc’;" onmouseout="this.style.backgroundColor=’#ffffff’;"> <td align="center" width="125"><a href="#">HelpDesk</a></td> </tr> <tr onmouseover="this.style.backgroundColor=’#cccccc’;" onmouseout="this.style.backgroundColor=’#ffffff’;"> <td align="center" width="125"><a href="#">Company Directory</a></td> </tr> <tr onmouseover="this.style.backgroundColor=’#cccccc’;" onmouseout="this.style.backgroundColor=’#ffffff’;"> <td align="center" width="125"><a href="#">Employee Store</a></td> </tr> <tr onmouseover="this.style.backgroundColor=’#cccccc’;" onmouseout="this.style.backgroundColor=’#ffffff’;"> <td align="center" width="125"><a href="#">Admin</a></td> </tr> </table>
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.