Template Extension
The template extension provides the basic capability for creating template MooseDocs markdown files. For example, this extension is used by the Software Quality Assurance Extension to help minimize the burden of creating SQA documentation. Templates allow custom substitutions to be made into markdown files, using two methods:
Key/value pairs: Simple substitution of key/value pairs via a syntax
{{keyname}}
.Fields: Substitution of entire blocks of markdown text/input.
The commands associated the template extension are the following:
template load
: Loads a template file. This is required to use any templates.template field
: Declares a template "field" that must be defined with thetemplate item
command.template item
: Defines a template "field" that was declared with thetemplate field
command.
Configuration
The available configuration options for the extension are given in Table 1.
Table 1: Configuration options for the template extension.
Key | Default | Description |
---|---|---|
active | False | Toggle for disabling the extension. This only changes the initial active state, use setActive to control at runtime. |
args | {} | Key value pair template arguments to be applied. The key should exist within the template file as {{key}}, which is replaced by value when loaded. |
The "args" configuration option can be used to set default values for key/value pairs. For example, a template argument "company" exists in the configuration for MOOSE for use in the following examples:
Using a Template
To use a template, it must be loaded with the required fields defined. Assuming that the example in Example 2 is named "example.md.template", it can be loaded and modified as shown in Example 1.
Notice that the command includes a key/value argument "model=Mustang". Any keys not given a value in the configuration must have their values specified as arguments in this way. Additionally, values specified in the configuration may be overridden in this way as well. Thus, in this example it would be possible to override the default for "company" by also supplying it to the load command.
As opposed to "keys", "fields" have their value defined by the template item
command. Here the field named details
(declared in Example 2) has its value defined. Note that field definitions may use key/values in their body.
Field definitions via template item
may use key/value pairs in their body; however, if !include
is used to include a portion of another file containing the usage of a key/value pair, then the text {{keyname}}
will be rendered literally instead of making the substitution, even if keyname
exists in both files. For example, the following does not render properly:
file1.md
:file2.md
:
Recall that MooseDown provides the syntax
for a command somecommand
that needs to include blank lines (for example, when there are multiple paragraphs or nested commands).
The complete list of settings for the "template item" command are provided in Table 2.
Table 2: Available settings for the 'template item' command.
Key | Default | Description |
---|---|---|
style | None | The style settings that are passed to rendered HTML tag. |
class | None | The class settings to be passed to rendered HTML tag. |
id | None | The class settings to be passed to the rendered tag. |
key | None | The name of the template item which the content is to replace. |
Creating a Template
To create a template file, start by creating a new file with the extension .md.template
.
Usage of the file extension .md.template
avoids the raw template file from being rendered and added to documentation.
Next, add content as in any other .md
file, using the syntax {{keyname}}
where you want to substitute a template parameter with the key name keyname
. Then when the template is loaded, the key keyname
will be required to have its value defined.
Use template field
to declare a "field" with the name specified by the key
argument (do not confuse with key/value arguments). The text following this command is the text that appears in an error box when the template is loaded without defining the field's value via template item
.
The complete list of settings for the "template field" command are provided in Table 3.
Table 3: Available settings for the 'template field' command.
Key | Default | Description |
---|---|---|
style | None | The style settings that are passed to rendered HTML tag. |
class | None | The class settings to be passed to rendered HTML tag. |
id | None | The class settings to be passed to the rendered tag. |
key | None | The name of the template item which the content is to replace. |
required | True | The section is required. |