The Grantlee template system
Speaker: Stephen Kelly
The Grantlee Template System is a port of the Django Template System[1] to Qt. The intent of the system is to encourage a clean separation of application and presentation logic, and to take the presentation of information out of the hands of developers and into the hands of artists.
Currently, many KDE applications create content for display or export using the QTextDocument system, or simply by building a string of markup like html, and rendering that for the user. Some applications allow customization of the appearance of the generated output by either allowing the user to specify custom css, or by changing the generated html based on user configuration. For example, KMail allows configuration of the email view with 'Fancy Headers', 'Enterprise Headers', 'Brief Headers' and several others. Kopete allows for more user control as it contains a theming system which allows users to write html themes. The Kopete system only allows variable substitution however. It doesn't provide any mechanism for conditionals or loops for example.
Using the Grantlee Template System it is possible to let artists or users completely customize the appearance or theme of generated output. Potential users of the system include KJots, KMail, KNode, and Kexi for generating reports. As the system depends only on QtCore, QtPlugin and QtScript, the system could be used by many more applications beyond KDE.
The template system works by using QObject introspection and the QVariant system to resolve variables in a supplied context. As in the Django system, variables may be resolved to multiple levels of depth. For example, if obj is an instance of MyObject with a property myProp which returns a list, then {{ obj.myProp.1 }} will resolve to the item at index 1 of the list.
The template syntax may be extended by application developers to meet specific needs by using the Qt Plugin system to write a tag library.
My talk will center around an introduction to the template syntax, how to take advantage of the system in a KDE application, and how to extend the template syntax to support application specific uses.
[1] http://docs.djangoproject.com/en/dev/ref/templates/
Stephen Kelly
Stephen Kelly is a KDE contributor since 2007. Since that time he has been the maintainer of the KJots note taking application and a developer on the Akonadi cross-desktop PIM infrastructure project. He has also contributed in areas of technical documentation and promotion.