Data templating

Data templating is similar to textual templating, but within a key:value pair framework.

Y: Data templating overview

Templates have been used for decades. Some early templates were used in the '80s to create mass-mailed form letters. These document templates continue to be used to this day. The concept has been expanded to HTML. Twig, moustache, and even PHP itself are all examples of HTML templating systems.

The idea is that you take your standard formatting principles (like HTML tags), and then create a system for embedding some extraneous logic in it so that an interpreter can format or otherwise output a dynamic result. Twig, moustache, and PHP are all different syntaxes for embedding sets of logic in HTML.

Y implements a new templating concept called "data templating" which works within the framework of key-value pairs. In data templating, you don't use any particular format (though YAML and JSON are both excellent methods for expressing key:value pairs).

The logic is expressed as particularly formatted strings and embedded text sequences. The format of these strings and text sequences is dependent on your data-templating implementation.

The Y system uses a syntax called Voom.

4 / 2019
Y: Voom

Voom is a key:value-pair data-templating syntax included with the Y module for Drupal and YAD7. It is influenced by C, assembly language, Perl, and Bash syntaxes.

The main concept behind Voom is to define a key:value-based logic and flow syntax that embeds with data to define dynamic arrays.

Voom syntax is a string that starts with this:

  • start character - The forward slash '/' has been arbitrarly chosen as the identifier for logic.
  • delimiter - The slash is followed by a delimiter which will separate elements of logic.
  • action character - Characters such as '?', '*', '@', '$', and '-' indicate conditional, loop, assignment, value retrieval, and plugin within the Voom syntax.
  • parameters - all actions have different parameter sets. These follow the action character.

Voom syntax can be embedded in an arbitrary string by enclosing it in brackets ('[' and ']')

Here is an example of a Voom variable assignment expressed in YAML:

//@myvariable: 2

It means:

assign 2 to a variable called @myvariable.

4 / 2019