# Editor Template

###### Identifier:

org.eclipse.ui.editors.templates

###### Since:

3.0

###### Description:

Templates are snippets of text or code which help the user enter reoccurring patterns into a text editor. Templates may contain variables which are resolved in the context where the template is inserted.

###### Configuration Markup:

<!ELEMENT extension (template* , resolver* , contextType* , include* , contextTypeRegistry*)>

<!ATTLIST extension

point CDATA #REQUIRED

id CDATA #IMPLIED

name CDATA #IMPLIED>

- point - a fully qualified identifier of the target extension point
- id - an optional identifier of the extension instance
- name - an optional name of the extension instance

<!ELEMENT contextType EMPTY>

<!ATTLIST contextType

id CDATA #REQUIRED

class CDATA #REQUIRED

name CDATA #IMPLIED

registryId IDREF #IMPLIED>

A context type defines a context within which templates are evaluated. A context type uses its resolvers to resolve a template.

- id - unambiguously identifies this context type. Use of a qualified name is recommended.
- class - a subclass of `org.eclipse.jface.text.templates.TemplateContextType`
- name - the display name of this context
- registryId - the id of the context type registry where this context type is automatically registered. Since 3.5.

<!ELEMENT resolver EMPTY>

<!ATTLIST resolver

contextTypeId IDREF #REQUIRED

type CDATA #REQUIRED

class CDATA #REQUIRED

description CDATA #IMPLIED

name CDATA #IMPLIED

icon CDATA #IMPLIED>

A template variable resolver can resolve a template variable in a certain context.

- contextTypeId - references the context type that this resolver is contributed to
- type - the type of this variable resolver. This property will be set on the resolver once it gets created.
- class - a subclass of `org.eclipse.jface.text.templates.TemplateVariableResolver`
- description - the description of this variable resolver. This property will be set on the resolver once it gets created.
- name - the display name of this resolver
- icon - an icon that may be displayed in the user interface

<!ELEMENT template (pattern)>

<!ATTLIST template

id CDATA #REQUIRED

contextTypeId IDREF #REQUIRED

name CDATA #REQUIRED

description CDATA #IMPLIED

icon CDATA #IMPLIED

autoinsert (true | false) "true">

A template is a snippet of code or text that will be evaluated in a given context. Variables which will be resolved in that context can be specified using the `${variable_type}` notation.

- id - unambiguously identifies this template. Use of a qualified name is recommended.
- contextTypeId - references the context type that this template is contributed to
- name - the internationalizable name of the template which will show up in the UI, such as in template proposals
- description - the description of this template
- icon - an icon that may be displayed in the UI for this template, for example in content assist proposals
- autoinsert - `true` (default) to make the template automatically insertable, `false` to not allow automatic insertion. Since 3.1.

<!ELEMENT pattern (#PCDATA)>

The template pattern.

<!ELEMENT include EMPTY>

<!ATTLIST include

file CDATA #REQUIRED

translations CDATA #IMPLIED>

A collection of templates encoded as XML can be included as a whole via this element.

- file - the XML file to import templates from. It defines at least one <template> element inside <templates>...</templates>, with the following attributes:
  - id - the uniqe id
  - name - the name
  - context - the context id
  - description - the description (optional, default: "")
  - autoinsert (optional, default: true)
  - enabled (optional, default: true)
  See above template element for more details about those attributes.
- translations - an optional properties file with resources for the templates specified in `file`.
  Note: The translation files are not treated as resource bundles and hence the file name has to be left as is i.e. do not add the locale to the file name. The translated files must be in the 'nl' directory i.e. if a [plugin] defines a template translations file in its plugin.xml like:

      ...
        translations=$nl$/[plugin-relative path to file]
      ...

  then the translations must go into:

        [plugins nl fragment]/nl/[locale]/templates/[plugin-relative path to file]

<!ELEMENT contextTypeRegistry EMPTY>

<!ATTLIST contextTypeRegistry

id CDATA #IMPLIED>

Defines a registry for context types. Context types which define a 'registryId' are automatically added to the registry which is created by `new org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry(registryId)`. Since 3.5.

- id - the id of this registry

###### Examples:

       <extension
             point="org.eclipse.ui.editors.templates">
          <template
             name="%ant.tasks.javac.name"
             contextTypeId="org.eclipse.ui.examples.templateeditor.antcontext"
             id="org.eclipse.ui.examples.templateeditor.templates.javac"
             description="%ant.tasks.javac.description">
              <pattern>
                 <javac srcdir="${src}"
                   destdir="${dst}"
                   classpath="${classpath}"
                   debug="${debug}"/>
              </pattern>
          </template>

          <resolver
             contextTypeId="org.eclipse.ui.examples.templateeditor.antcontext"
             type="src"
             class="org.eclipse.ui.examples.templateeditor.editors.AntVariableResolver">
          </resolver>

          <resolver
             contextTypeId="org.eclipse.ui.examples.templateeditor.antcontext"
             type="dst"
             class="org.eclipse.ui.examples.templateeditor.editors.AntVariableResolver">
          </resolver>
       </extension>

###### API Information:

See the `org.eclipse.jface.text.templates` package in the `org.eclipse.text` plug-in for the relevant API.

###### Supplied Implementation:

See the `org.eclipse.jface.text.templates` package in the `org.eclipse.text` plug-in for the relevant classes.

Copyright (c) 2001, 2010 IBM Corporation and others.
This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which accompanies this distribution, and is available at https://www.eclipse.org/legal/epl-v20.html/ SPDX-License-Identifier: EPL-2.0