Template Libraries

Creating inline markup within an OpenSocial template can be an excellent option for small-scale applications, where developing simple tags may help provide some measure of reusability in the code base. Even though this is a fine approach, as the application logic increases in complexity and you create more and more custom tags, you may need to separate out a gadget’s reusable logic even further. Template libraries can help you do this.

Template libraries are standalone XML files that provide a gadget with functionality such as:

  • Global JavaScript functions

  • Global styles

  • Simple custom tags with simple markup

  • Complex custom tags with markup, local CSS, and local JavaScript

Template libraries provide a central location for global JavaScript, CSS, and tags that may be reused throughout the program flow. Using them can help to reduce code bloat, make the gadget easier to work with, and make debugging easier.

Creating a template library

A template library is a standalone XML file containing a number of sections that you can use to define fully enclosed custom tags or global functionality for the gadget. The XML template file follows a standardized template syntax with a number of potential sections and functions:

<Templates xmlns:temp="http://www.mysite.com/temp"> <Namespace prefix="temp" url="http://www.mysite.com/temp"/> <Style> <!-- global library styles --> .inlineText { font:11px arial,helvetica,sans-serif; color:#c0c0c0; } </Style> <JavaScript> <!-- global library functions ...

Get Programming Social Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.