You can create snippets from scratch using the Snippets panel or by highlighting a desired block and saving the selection. You can insert saved snippets into your pages as a block or wrap them around a selection of code. Once a snippet has been saved, you can then assign a keyboard shortcut to it. This additional functionality makes snippets ideal for performing tasks such as filtering CSS from certain browsers, like Internet Explorer. Simply highlight the CSS styles you want to filter and wrap the snippet around the selected block. I have included several CSS filter and hack snippets in the extension in the sample files linked from the beginning of this article.
While on the surface, snippets may seem similar to Dreamweaver Library items, which again enable you to insert fragments of code, there is a significant difference between Library items and snippets. Library items (and for that matter Templates) use instance architecture, meaning that when you insert a library item into a page you are create an instance of that file, which in turn can be automatically updated if the source file changes. Snippets, on the other hand cannot be automatically updated since you are not creating an instance of the snippet. When inserting a snippet you are simply adding a fragment of code to a file. If you update a code snippet, it doesn’t automatically update the code snippets you inserted into any file; to update that code, you must perform a find and replace on your files.
Sooner or later you'll probably find that you want to distribute your snippets both to and from work colleagues or computers at different locations. For example, having accumulated a large number of snippets on your workstation in the office, you may want to transfers the files to your laptop or home computer. Although Dreamweaver doesn't offer an export snippet option through the Snippets panel, distributing Snippets isn't as arduous as it may seem. Once you know that snippets use the CSN file suffix, tracking them down is relatively simple.
To locate and copy snippets you have created, use the following steps:
Browse to locate the Dreamweaver MX 2004 folder, which you can find by following this path:
C:\Documents and Settings \<Username>\Application Data\Macromedia\Dreamweaver MX 2004\Configuration\Snippets\.Browse to locate the Dreamweaver MX 2004 folder, which you can find by following this path:
..\Documents and Settings \<Username>\Macromedia\Dreamweaver MX 2004\Configuration\Snippets\.
To locate and copy snippets that ship with Dreamweaver MX 2004, do the following:
Browse to locate the Dreamweaver MX 2004 folder, which you can find by following this path:
C:\Program Files \ Macromedia\Dreamweaver MX 2004\Configuration\Snippets\.
Browse to locate the Dreamweaver MX 2004 folder, which you can find by following this path:
C:\Documents and Settings \<Username>\Macromedia\Dreamweaver MX 2004\Configuration\Snippets\.
Once you have located the snippet(s) you want to distribute, you can simply copy and paste them into the Snippets folder on the machine you want to distribute them to.
Note: Dreamweaver MX 2004 does not store keyboard shortcut information inside the snippet files. This is stored in another file called Menus.xml, so none of the keyboard shortcuts you have assigned to your snippets will work once copied to their desired location. While this may be acceptable for distributing snippets to work colleagues, if you are copying snippets to your workstation at home, you may also want to include the keyboard shortcut information. To accomplish this, you have two options: