Using Code Snippets
Web designers commonly reuse code in several pages. Whether you’re reusing a single line of code or a code block, you need to avoid typos at all costs. Code snippets can prevent typos and add a high degree of convenience to code reuse.
To insert a code snippet into your page, you can use the Snippets panel, as shown in Figure 3.17. (If the Snippets panel isn’t visible, select Panels, Snippets to display it.) Switch to Code View and double-click on the desired code snippet to add it to your page.
Figure 3.17. Code snippets can be added easily by pressing Ctrl+Enter while in Code View.
You can also press Ctrl+Enter while in Code View to display a pop-up of your code snippets. Select a code snippet from the list and press Enter to insert it into your page.
You can easily add, delete, or modify code snippets using the Snippets panel. You can add a new code snippet by clicking Options, New Snippet and entering the required information. You can control where the insertion point appears after inserting the snippet by adding a pipe symbol (|) to the snippet code. If you add two pipe symbols, all code between the two pipe symbols is automatically selected when the snippet is inserted.
When you add your own snippets, they are stored in an XML file located in the AppData\Roaming\Microsoft\Expression\Web 4\Snippets folder in your profile directory. To move your snippets to another machine or back them up (something I strongly recommend), you can simply back up the Snippets.xml file in the Snippets folder.
Figure 3.18. Code snippets make reusing code convenient. Expression Web comes with plenty of existing snippets.