XHTML Skeleton Loader

Skeleton files are very similar to MillScript templates, except they use named, rather than numbered, parameters. They are also written in XHTML augmented with some custom tags. It would also be easy to write new custom tags in MillScript (or even in Java) to capture some common design motif.

Skeleton files are found in the inventory and are given the extension ".sk". A skeleton can be a tiny document fragment or an entire page. In either case, they are compiled into a MillScript function and assigned to a variable whose name matches that of the file. So, if you see a skeleton file "menu.sk" you can access it in MillScript through the variable "menu". Simply referring to that variable will cause MillScript to search the inventory and autoload the relevant file.

We call the compiled function the "skeleton function" in order to distinguish it from the "skeleton file".

Almost always, skeletons require arguments. These can be passed in as arguments to the skeleton function. Unlike a template where arguments are numbered, a skeleton has named arguments.

Unlike a template, where the template function arguments are gathered up into a list, skeleton function arguments are used to construct a map. In fact the skeleton function behaves in a similar way to the newMap* functions, except rather than returning a map variation it returns the filled in template. Hence only maps, maplets or lists are valid as arguments to the skeleton function. The resulting map is a mapping of argument name to argument value.

Arguments are specified by the field element, or indexing the arg map inside an item element, or referring to the argument name inside a special attribute value(which begins with "?" and is followed by the argument name). You can also refer to arguments within comments, using the same percent syntax as in a template(e.g. %1p maps to the value of the first key-value pair argument to the skeleton, %2p maps to the second value, etc).

In order to make it possible to view a skeleton in a browser, most custom tags only look at their attributes and ignore their children. As a result, you can insert helpful text inside a custom tag so that a browser, such as navigator or explorer, will ignore the unknown tag but display the useful text.

File Format

Skeletons are written in XHTML augmented with some custom tags, to access skeleton arguments and execute millscript code.

Skeleton arguments are generally accessed by the field element, e.g.

<field name="header"/>
        

As you have probably already guessed, the "name" attribute specifies the argument by name. You can also use these named arguments to substitute element attributes. Let us suppose you wanted to make the "bgcolor" attribute of the body element, e.g.

<html>
  <head>
  </head>
  <body bgcolor="?color">
    <field name="body"><i>The contents go here</i></field>
  </body>
</html>
        

The key is the use of the initial "?". This signals to the template compiler that the attribute is not a literal string but a reference to a named argument.

These arguments are bound to a map called arg and can be accessed as arg[name]. This means they can be incorporated into expressions using the features described below.

To substitute a MillScript expression you should use the "item" element. This has a single attribute named "val" whose value is expected to be a simple MillScript expression. e.g. To substitute the variable "mainBody" into the body of a template we would write something like this;

<html>
  <head>
  </head>
  <body bgcolor="?color">
    <item val="mainBody">
      Substitute mainBody here
    </item>
  </body>
</html>
        

Note that we do not need the leading "?" this time (although if you put it in it does not matter, it is simply stripped off.) That is because "item" knows that the value of the "val" attribute is always MillScript and never a plain string.

Use

  1. Create an sk file in your inventory, containing the required XHTML, arguments and expressions, as detailed in the file format. e.g Lets assume you create a file called simple.sk.
    <html>
      <head>
      </head>
      <body bgcolor="?color">
        <field name="body">The template body</field>
        <!-- First arg value: %1p, Second arg value: %2p -->
      </body>
    </html>
                
  2. To use the connection within a script, we just have to refer to the name of the tp file, e.g.
    simple
                
    and this will load the template for us.
  3. To fill in the template, we apply the template function, passing the required number of arguments and ensuring any variables required by expressions are defined, eg.
    simple(
      "color" ==> "#FEFEFE",
      "body"  ==> <b>"the replacement body text"</b>
    );
                
    The application of the template function, simple, would return:
    <html>
      <head>
      </head>
      <body bgcolor="#FEFEFE">
        <b>"the replacement body text"</b>
        <!-- First arg value: #FEFEFE, Second arg value: the replacement body text -->
      </body>
    </html>
                

Notes