# Adding a new Snippet [edit]

This page describes how to add a new snippet to the Snippets View.

## Introduction

In addition to the default snippets that Aptana includes in the Snippets View, you can also create your own re-usable custom snippets for pieces of code that you frequently type. For example, if you always use the same set of styles for preformatted code, you could create a CSS Snippet that defines the <pre> tag, or if you use Dreamweaver's templates feature, you could even define your own HTML Snippet to use as a template for your HTML files.

## Instructions

Note: You must have a file (any kind of file--HTML, JS, etc) open in one of the Aptana Editors to create a snippet. This file will not be affected by your snippet creation.

To create your own snippet:

1. In any top-level folder of your Project View, create a folder named snippets (you only need to do this the first time that you create a snippet).
2. In your snippets folder, create a new file for the type of snippet that you are creating (e.g. ".html" for an HTML snippet).
3. Either use one of the existing snippets as a model for content, or place your cursor at the top of your file and run the appropriate template snippet from the Snippets Template folder to create the appropriate template shell for you.
4. If you would like your snippet to prompt you or another user for any sort of a variable (such as a file name or URL), add the text `prompt(var_name): promptText` where var_name is the name of the variable and promptText is the text that you want the Snippet to prompt the user with.

   Open the Insert Quicktime Movie Snippet for editing to see an example of this. The variable name must be in lower case.

5. Below the closing comment marker for your file type, type the exact text/code that you want inserted when you insert your Snippet.
   - If you used prompt to assign a variable earlier, you can then use `${var_name}` anywhere in your Snippet code to use that variable. See the Insert Quicktime Movie Snippet for an example.
   - If you want your Snippet to act on text that you or another user selects, add your Snippet text around a `${selection}`. For an example of this see any of the HTML Wrap with <tagName> Snippets variable.
6. Save your changes.

## Related Topics

- About Aptana Snippets
- Editing with Snippets
- Editing a Snippet

Retrieved from "http://aptana.com/docs/index.php/Adding_a_new_Snippet"

Category: AptanaHelp