User:Krauss/arXiv-1/Hooks


 * This article is a supplement to the Delimiting and embedding strategies.

On web templates the separation of concerns (content from presentation) require a low-level separation strategy to isolate template language from output language.

Template syntax needs special care with the "border" between languages, in order to avoid mixing and to supply scaping forms. There are well defined tags, marks or characters, named "hooks", that intend to separate (compatibilize) the two languages.

Types of hook:
 * Script hooks: encloses blocks of developer-supplied program logic.
 * Sub-template hooks: to fix the frontiers of the sub-template block.
 * Expression hooks: to encode scalar variables, sub-template references, or expressions.

Note: formally, all template language need clear rules for "clean-up (or extract) the template language" from the output language. Hooks, scripts and expressions are extracted with the Clear(T) function.

There are a height diversity of implemented styles for hook encoding, and there are also web template systems with options to reconfigure hooks.

The listings below show the hooks styles used on the web template system's examples.

Hook implemented notations
There are many styles of notations implemented (or configurable) on web template systems. To referentiate then on other articles, "style labels" was supplied.

Script hooks
Usual script hooks:, for instructions block.

Many template languages not offer syntax to separate blocks, or offer a syntax option to express isolate instructions. Single-instruction hooks:

Many offer the possibility of define sub-templates (or other instructions) into the instruction body Instruction hooks with sub-templates:

Sub-template hooks
See also Directive hooks with sub-templates, where, usually, the sub-templates are not-referenciable.

(referenciable) Sub-template hooks, to sub-template block definition:

Expression hooks
Generic expression hooks:

For more specific expression hooks, there are cases where a "hook notation" is used, and others where a "internal template language syntax" is used. When "internal", may be important important also for presentation users of the template language (see separation of concerns needs).

Specific function-call expression hooks examples:

Many template inlanguages offer also an internal syntax expression to interpolate strings. They use internal notation, like "string-hooks", for separation. Examples for specific expressions with interpolations:

Hook diversity
Basic factors:
 * 1) It is very ease to implement template engines to simple substitution template languages.  If the application grow, and need more sophisticated language, it will be compatible with the first versions.
 * 2) The web template final user is, usually, a web designer. He/she deals with the templates through a web editor, like Dreamweaver. There are many editors and web designer needs may force template language to adapt to the editor's restrictions.

XML hook uniformazation tendency
There are a tendency on template languages to compatibilize hooks with the XML syntax rules. On XML it is possible to embed many languages together. A language namespace for tag names, are defined by prefix.

JSP example, for "specific hook notation" Versus "XML notation" (from the J2EE 1.4 tutorial):

Another way to embed template language on XML languages, is to add special/reserved attributes. See Attribute languages.