« Home

Gordian Templating

You may find yourself frequently reusing a block of layout, such as a monster stat block, skill check, or shop. In this case you can use a template to store the layout and reusse it.

Defining a Template

Templates are declared inside the gb-templates passage. The passage can contain one or more <template> tags. For example:

To use a template in a passage, use the <t> tag:

This would outout whatever the content of the template test is (in this case [CONTENT]).

For example

Given a template, 'dead':

And a passage content of:

You would see:

If you prefer you can use the syntax <template name="template_name"></template>.

Passing Content to a Template

A template with fixed text has limited uses (though not none). More often you will want to pass some content to a template. For example imagine you have a specially styled div in your game for notes, and want to use that frequently. You could set up a template and pass the content of the note.

In this template the text {{default}} is going to be replaced with the default content of the template, which is everything between the <t> and </t> tags.

{{default}} is actually a specical case variable, supplied when there are no other variables inside the data passed to the template. Instead of just passing some text, you can pass a JSON object of values.

You can access values from the object by putting the key in {{}} as shown above. If your data has nested values (arrays, or other objects) you can access them with "dot notation", for example: {{weapon.damage}} {{weapons.0}}.

Conditionals in Templates

You may wish to vary the layout of your template depending on the data passed — if X then Y, for example. You can do that using the <if> tag inside your template.

You can use the following for comparisons:

== equals
>= greater than or equals
<= less than or equals
> greater than
< less than
!= not equals

The following logical operations are also available: or, and, not. So this is valid:

Repeating Content

One of the best features of a template is repeating layout. For example, you might lay out images in a gallery, or lines of information in a shop. You can do this using the <repeat> tag. The simplest form of this repeats its contents a fixed number of times.

The number of repeats can come from a variable, as usual.

Alternatively you can loop over the contents of a variable doing something for each value.

In this sort of loop (<repeat ARRAY as VARIABLE>) ARRAY is the thing you are looping through and VARIABLE is a name assigned to it.

For example

Given a template, 'gallery':

And a passage content of:

You would see:

When working with <repeat> some special variables are available.

LOOPNAME is the name of the repeat, which is the same as the variable you are repeating over, with any dots replaced by underscores. For example <repeat bags as bag> generates bags_length and bags_index. <repeat items.bags as bag> generates items_bags_length and items_bags_index.


In-game shop

Data looks like:

Image Gallery

Data looks like:

Full page image