Template Language Introduction

A lesson consists of a sequence of sections. Each section consists of building blocks. Every block has a set of attributes.

Throughout these documents, we use the following formatting convention:

  • block types are gray
  • block attributes are yellow
  • JavaScript functions, function parameters, and other variables are green
  • other values are blue

Every section is constructed from a template. The template defines the blocks used to create the section. One template can be used to create multiple sections (a section is an instantiation of a template). A template can define parameters that vary between sections (i.e., that vary between instantiations of the template).

A block is defined by giving a block type followed by a series of indented lines specifying block attributes:

    title A Section Title
    text This is an instruction.
    initValue 1
    decimalPlaces 2

All block types, block names, and attribute names are case sensitive. Any attribute can span multiple lines by leaving the attribute value off of the first line and adding an end marker after the last line:

        This is an instruction block
        with a multi-line text attribute.
        Any attribute can have multiple lines
        followed by an "end" tag.

If a block has a label attribute, but no name attribute, the name will be computed from the label. For example, a block with a label of X Velocity will automatically be named xVelocity unless a name attribute is specified. Any block without a specified label and without a specified name will be assigned some name.

You can define a macro using this syntax:

define $macroName value

Subsequently, all instances of $macroName will be replaced with value (direct text substitution, no parameterized macros currently). Macros are only intended for constant values.

A template parameter is defined using a similar syntax:

parameter $parameterName defaultValue

A parameter may vary from section to section (whereas a macro is fixed between all instances of template).

The system has some built-in special expressions. The expression @self refers to the name of the current block. If a ControlBlock is defined, the expression @dt gives the duration of each simulation step in seconds (1 divided by updatesPerSecond). The expressions @leftArrow, @rightArrow, @upArrow, and @downArrow insert arrow symbols.

You can import a block from another template in the same lesson using the importBlock command:

importBlock templateName.blockName

This requires that the name attribute be specified on the Template block in the source template.

Note: in a template, all text following a # symbol is a comment.