Template hierarchy

Template hierarchies are naturally formed whenever one template (the super-template) references another template (the sub-template). Such references occur in the following types of fields:

Example

Template A includes template B1, attaches template B2 and uses template B3.
Template B1 both includes and attaches template C1.
Template B2 includes template C1 and attaches template C2.

Variables in template hierarchies

Information about variables can flow both up the hierarchy and down the hierarchy.
Variable information flows up the hierarchy whenever a sub-template defines a variable in its dictionary which does not occur in the super-template's dictionary, or when it is defined as a computation in the sub-template and as a question in the super-template.
Variable information flows down the hierarchy whenever a super-template defines a computation variable, either in its dictionary or within the include/attach/using field, and that variable is a question variable in the sub-template.

Variable definition flows up

Consider the example hierarchy above.
If a variable (question or computation) is defined in template C1 but not in templates A, B1 or B2 then that definition flows up the hierarchy to those super-templates.
If a computation variable is defined in both templates C1 and B2 but not in templates A or B1, then its definition in C1 flows up to B1 and from there up to A but it does not overwrite the definition in B2. However, if it is defined as a computation variable in C1 and as a question variable in B2 then the definition in B2 is overwritten by the definition in C1.

Variable definition flows down

Consider the example hierarchy above.
If a variable is defined as a question variable in template C1 then it can become a computation variable when that sub-template is used in one of its super-templates B1, B2 or A. Note that when sub-template C1 is used stand-alone the variable will still be considered as a question variable.
The definition can be acquired from one of the following:
(1) the include field of C1 in template B1, or
(2) the attach field of C1 in template B1, or
(3) the dictionary of B1, or
(4) the include field of C1 in template B2, or
(5) the dictionary of B2, or
(6) the include field of B1 in template A, or
(7) the attach field of B2 in template A, or
(8) the dictionary of A

Consolidation

Consolidation is the process of building and caching a single unified representation of an entire template hierarchy.
Consider the example hierarchy above where all templates have been uploaded. The following consolidation processes will occur:
  • the uploaded template B3 will be consolidated stand-alone
    to produce the consolidated template B3
  • the uploaded template C1 will be consolidated stand-alone
    to produce the consolidated template C1
  • the uploaded template C2 will be consolidated stand-alone
    to produce the consolidated template C2
  • the uploaded super-template B1 will be consolidated with its consolidated sub-template C1
    to produce the consolidated template B1
  • the uploaded super-template B2 will be consolidated with its consolidated sub-templates C1 and C2
    to produce the consolidated template B2
  • the uploaded super-template A will be consolidated with its consolidated sub-templates B1, B2 and B3
    to produce the consolidated template A
The consolidation process is invoked the first time a template is launched. You may notice, therefore, that the first launch after uploading is slower than subsequent launches because of the consolidation process.

Questionnaire Order and Hierarchies

When thinking of defining questionnaires in a template hierarchy it is important to remember that the questionnaire from the template that is launched will take precedence over those in lower level templates. This means it may be best practice to have the questionnaire order defined in the top template only and remove any local questionnaires from lower level templates.