Edgewall Software
Version 5 (modified by cmlenz, 8 years ago)

--

Markup Templates

The markup package provides a template engine that is compatible with Kid ( http://kid.lesscode.org) to a certain extent.

Common concepts and features:

  • The same basic set of directives (excluding py:extends and py:layout)
  • Inline expressions using the ${expr} (or just $expr) syntax.
  • Expressions are real Python code, not some “crippled” mini language.
  • Stream-based processing model making heavy use of Python generators.
  • Different serialization methods, for example to produce XML or HTML output.

Differences include:

  • No generation of Python code for a template; the template is executed directly.
  • No support for <?python ?> processing instructions
  • Expressions are evaluated in a more flexible manner, meaning you can use e.g. dotten notation to access items in a dictionary, and the other way around (see the markup.eval module)
  • Proper scoping of variables. Names do not leak into outer scopes.
  • Use of XInclude and match templates instead of Kid's py:extends / py:layout directives
  • py:match directives use (basic) XPath expressions to match against input nodes, making match templates more powerful while keeping the syntax simple (see the markup.path module)
  • Real (thread-safe) search path support
  • No dependency on ElementTree (due to the lack of position reporting)
  • The original location of parse events is kept throughout the processing pipeline, so that errors can be tracked back to a specific line/column in the template file
  • In simple tests (see examples/basic) the rendering phase (i.e. not including parsing/compilation) runs about twice as fast compared to Kid. Parsing is generally quite a bit faster in Markup, too.