Aptana Studio ヘルプ > はじめに > Aptana Studioナビ > Aptana Snippets

Adding a new Snippet

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

Contents

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 blank new file for the type of snippet that you are creating (e.g. ".html" for an HTML snippet). This file should be completely blank. Delete any default content that was added when Aptana created the file.
  3. Create your snippet content:
    1. Place your cursor at the top of the empty file that you just created.
    2. In the Snippets View, expand the Snippet Templates folder.
    3. Double-click the snippet template for the type of snippet that you are creating (e.g. "HTML Snippet Template" for an HTML snippet).

      Aptana runs the snippet and creates a shell for your snippet code.

      Alternatively, if you want to create a snippet that is similar to an existing snippet, you can simply copy-and-paste the content of that snippet into your blank file and modify it.

  4. Add your snippet code. You can reference the existing snippets to see examples of how to code a snippet.
  5. 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.

  6. 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.
  7. Save your changes.

    Aptana will file your new snippet in the Snippets View in the appropriate folder (e.g. in the HTML folder for an HTML snippet.

To run your new snippet, navigate to your snippet in the Snippets View and double-click your snippet.

Adding a Snippet to the Toolbar

A snippet can be added to the toolbar of an editor based on mime type. An example snippet is shown below:

<!--
      category: HTML
      name: Wrap with 
      toolTip: Wrap with <strong>
        
      toolbar: true
      icon: strong.png
      language: text/html
-->
<strong>${selection}</strong>

The icon is a relative path. If you are distributing the snippet as part of a plugin to Aptana Studio, you'll want to put the full path, i.e. com.aptana.ide.snippets/icons/strong.png

Related Topics