Using Find and Replace


One of the most useful features in Dreamweaver is the Find and Replace dialog. Unlike most Find and Replace options included with word processing programs and the like, the Find and Replace dialog included with Dreamweaver allows you to search and then replace elements for an entire site, a current document, selected text, open documents, a specific folder, and even selected files within a site. Even better, you can use the Find and Replace dialog as a way to search for elements in source code, text in the Design or Code views, text within specific tags, or specific tags in general. Furthermore, the Find and Replace dialog doesn't require a page to be open before it's run; instead, you can open the dialog at any time while Dreamweaver is open. To open the dialog, choose Edit, Find and Replace or press Ctrl+F in Windows or Command+F on a Mac. The Find and Replace dialog opens, similar to Figure 14.9.

Figure 14.9. Use the Find and Replace dialog to search for various types of elements.


The basic Find and Replace dialog displays the following functionality:

  • Find in: Choose an option from this menu to set the location of the search. Options include searching selected text, a current document, open documents, a folder, selected files within a site, or the entire current local site.

  • Search: Choose an option from this menu to set the type of element you want to search for. Options include source code, text, advanced text (text and code combined), and a specific tag. When you select the Text (Advanced) or Specific Tag option, the Find and Replace interface changes to support selections of element types and element values, as shown in Figure 14.10.

    Figure 14.10. Selecting the Text (Advanced) or Specific Tag option causes the dialog to change in support of the selection of element types and element values.


  • Save/Load Query: After you perform a search (otherwise known as a query) you're happy with, you can save it by clicking the Save Query icon. This action launches the Save Query dialog, which allows you to save the query anywhere on your computer as a DWR file. Alternatively, you can load a saved query by clicking the Load Query icon. Doing this launches the Load Query dialog, which allows you to open an existing DWR file.

  • Find: Enter the element for which you want to search in this text box. In most cases, the element you enter here is plain text.

  • Replace: Enter the element with which you want to replace the searched-for element in this text box.

  • Options: Use the check boxes in this group to refine your search: You can specify the element to be searched matches the case of what you type into the Find text box. You can choose to search for what you type into the Find text box as a whole word or to ignore white space. If you know how to write regular expressions, check that box and type the regular expression into the Find text box.

  • Find Next/Find All: Use the Find Next button to step through the elements being searched for on a page-by-page basis. Each page is opened individually. Alternatively, click the Find All button to display all the results in a list within the Search tab of the Results panel.

  • Replace/Replace All: Use the Replace button to replace the searched value with the value entered in the Replace text box. Alternatively, click Replace All to replace all instances listed in the Results tab of the Results panel with the value in the Replace text box.

As a demonstration of the Find and Replace dialog's functionality, let's perform a couple of searches, one basic and one advanced. To perform the basic search, follow these steps:

1.

With the Find and Replace dialog open, select the Entire Current Local Site option from the Find In menu.

2.

Choose the Text option from the Search menu.

3.

Enter the text Dorknozzle into the Find text box.

4.

Disable the Match Case check box.

5.

Click the Find All button.

As you can see from Figure 14.11, the results of the search are displayed in the Search tab of the Results panel. The Matched Text column displays a short string of text, complete with the searched value underlined in red. In this example, remember that we searched for text in the local site. The companydirectory.htm page is the only page in our site that has the text Dorknozzle in the design. If you wanted to search for the text Dorknozzle in source code, you would get much broader results.

Figure 14.11. The results of the search are displayed in the Search tab of the Results window.


To make an edit to that page, simply double-click the row in the Result window. Doing this opens the page and highlights the matched text within the page. Of course, you can use the Replace and Replace All features to replace this string of text with something different. Because we just wanted to demonstrate the search functionality, we'll avoid the Replace and Replace All buttons.

Now let's do a more advanced search. In this next example, we'll search for text contained in a specific tag using the Text (Advanced) option. To do this, follow these steps:

1.

Reopen the Find and Replace dialog by choosing the Find and Replace option from the Edit menu. If the Results window is currently open, click the Play icon in the upper-left corner of the Search tab. Either method reopens the Find and Replace dialog.

2.

Make sure that the Entire Current Local Site option is selected from the Find In menu.

3.

Choose the Text (Advanced) option from the Search menu. The dialog's interface changes to accommodate entering text as well as selecting tag-searching values.

4.

Enter the text Dorknozzle into the Find text box.

5.

For this example, we want to search for all instances of the Dorknozzle text value contained in the <title> tag. Knowing this, select the Inside Tag option from the first menu and the title option from the second menu.

6.

Click the Find All button. Because we have only three pages, and all three pages contain titles with the text The Dorknozzle Company Intranet, the Search tab in the Results window displays three results.

As you can see, the Find and Replace dialog is powerful. It becomes extremely powerful when searching for specific tags. Assume for a moment that you have a site that contains 1,000 pages. Also assume that each page uses different style sheets, each created by a different department. What if you were asked to replace all style sheet references on every page to match a single style sheet reference called styles.css? You'd be working for hours, opening every page and changing the style reference to point to styles.css. Using the Specific Tag option in the Find and Replace dialog, however, this effort would be minimal. Figure 14.12 shows what the Find and Replace dialog might look like to accomplish this task.

Figure 14.12. Using the Specific Tag option, you can easily search for specific tags and attributes and then replace that tag or attribute with a custom value.


As you can see from Figure 14.12, our search would involve locating the <link> tag with the attribute HRef with the attribute value set to anything. The query might look like this:

 <link href="<anyvalue"> 

That value would be set to styles.css or:

 <link href="styles.css"> 

The possibilities are endless. You'll quickly notice that dozens, if not hundreds, of possibilities exist using the many options available in the menus.




Macromedia Dreamweaver 8 Unleashed
Macromedia Dreamweaver 8 Unleashed
ISBN: 0672327600
EAN: 2147483647
Year: 2005
Pages: 237
Authors: Zak Ruvalcaba

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