Next: Template Macros, Up: Templates [Index]

#### 5.2.1 Template Section Dictionaries

To add variable values to section dictionaries used within a specific template, you can add them to the beginning of the template declaration like this:

    template TEMPLATENAME :arg1 :arg2
    "Optional documentation string"
    sectiondictionary "A"
    set NAME "foo"
    ----
    A beginning line {{NAME}}
    {{#A}}Optional string {{NAME}} here{{/A}}
    An end line
    ----

In this example, the NAME variable gets the value “foo”, but only while it is inside section macro A. The outer scoped NAME will be empty.

This is particularly useful while using an include macro to pull in a second template. In this way, you can pass values known from one template to a subordinate template where some value is not known.

From the Emacs Lisp default template file, a syntax table is just a variable with a specialized value.

If a variable is declared like this (where $ is the escape character):

    template variable :el
    "Insert a variable.
    DOC is optional."
    ----
    (defvar $?NAME$ $^$
      "$DOC$")
    ----

then you can see that there is a NAME and DOC that is needed. The `^` point inserter is also a handy key here.

The syntax table wants a variable, but knows the values of some of these variables, and can recast the problem like this by using template specific `sectiondictionary` macro declarations.

    template syntax-table
    "Create a syntax table."
    sectiondictionary "A"
    set NAME macro "?MODESYM" "-mode-syntax-table"
    set DOC "Syntax table used in " macro "?MODESYM" " buffers."
    ----
    $<A:variable$
      (let ((table (make-syntax-table (standard-syntax-table))))
        (modify-syntax-entry ?\; ". 12"  table) ;; SEMI, Comment start ;;
        ;; ...
        table)
    $/A$
    ----

In this way, NAME can be set as a user posed question for MODESYM with “-mode-syntax-table” appended. A simplified doc string will also be inserted.

Lastly, the A section contains more macro text which is inserted at the `^` point marker.

By creating useful base templates for things like function or variable declarations, and recycling them in higher-order templates, an end user can override the basic declarator, and the higher order templates will then obey the new format, or perhaps even work in more than one major mode.

Next: Template Macros, Up: Templates [Index]