Alternative Template Expansions

This topic shows you how to enable Alternative Expansions for a template. You will specify several template expansions that will be used in different Contexts. The example starts with the vi?Type? template described in the Template Name Variables topic.

  1. Fill the Context field in the original template. It should expand when the clipboard does not contain an identifier. To check this, use the logically-inverted [HasIdentifier] Context Provider from the Editor | Clipboard group.
  2. Click the + button on the Template Expansion toolbar to add an Alternative Expansion.

    Ext_Templates_AltExp1

  3. Specify the context for this expansion. For instance, use the following context: "[Hasldentifier] && ![DeclaresLocal(«?Paste»)]". This expression checks whether or not the clipboard holds a valid identifier and this identifier is free in the current scope. If so, you can use this identifier to suggest the name for the new variable.

    Note

    To check if the identifier is declared locally, use the [DeclaresLocal(localName)] context provider from the Editor | Code group. You can use any String Provider as the Context Provider's parameter.

    Ext_Templates_AltExp2

  4. Add one more expansion to cover the case when the identifier in the clipboard is already declared. In this case, you can assign a new variable value without declaration.

    Ext_Templates_AltExp3

The template with three Alternative Expansions is now fully defined, and you can save and test it.

Ext_Templates_AltExp_Test_GIF