OpenSocial Templates are a tool which developers can use to easily build gadgets with relatively little of no Javascript coding. Templates make use of OpenSocial Markup Language (OSML) and Expression Language (EL) and are typically used in conjunction with Data Pipelining.
To use OpenSocial Templates developers must require the opensocial-template features
<Require feature="opensocial-templates"/>
Because OpenSocial Templates are typically used in conjunction with data pipelining developer should consider requiring this feature as well.
<Require feature="opensocial-data"/>
Template tags can be used either from within a <Templates> element
<Templates>
or the <Context> element by invoking them via script tags
<script type="text/os-template">
Defining templates via <Templates> element allows them to be accessible from all the different views. Templates defined this way are not rendered until they are called from within the Javascript gadget code.
Example:
Defining templates via <script type="text/os-template"> allows them to be place directly into the <Context> element and rendered via the gadget.
Example:
Data which is require for rendering the template. This is declared using the @require attribute.
Example
<script type="text/os-template" require="Viewer, Owner">
Hello, <os:Name person="${Viewer}"/>, welcome to <os:Name person="${Owner}"/>'s application
</script>
Because more OpenSocial Templates are rendering external data which may be changing frequently, OpenSocial templates offer a way to allow the template to be re-rendered anytime the required data changes. This is done via the @autoUpdate attribute.
Example
<os:Var> - Used to declare variables inline with the a template
${Top} - the data context passed into the template rendering
${Context} - holding area for template specific variables
${Cur} - The current data item being processed
${My} - Data passed into the template via a Custom XML Tag. This is only available in template that use Custom Tags
Content within templates can be displayed conditionally based on the value of an expression.
Conditions can be used in templates in two ways:
<os:If condition="${Condition.To.Test}">
This information you want to display conditionally
</os:If>
<div if="${Condition.To.Test}">The information you want to display conditionally</div>
<os:Repeat expression="${Top.ViewerFriends}">
<div>
Your friend's name is ${Cur.Name}
</div>
</os:Repeat>
<div repeat="${Top.ViewerFriends}">
Your friend's name is ${Cur.Name}
</div>
The OCLC Developer Network supports the use of OCLC Web Services—a set of tools and APIs that expose data and services for WorldCat and our member libraries and partner institutions or companies. learn more »
© 2010 OCLC Domestic and international trademarks and/or service marks of OCLC Online Computer Library Center, Inc. and its affiliates
Follow the OCLC Developer Network: