O'Reilly logo

Programming Social Applications by Jonathan LeBlanc

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Special Variables

OpenSocial has a set of reserved special variables for working with template data objects and processing the template. These variables—Context, Cur, My, and Top—each have different groups of data that they can access and a different order of precedence during loading. With the exception of ${Context}, special variables are not required when you’re referencing data. Since the variables are not required, expressions will be evaluated against the available special variables using the following precedence load order:

  1. ${Cur}

  2. ${My}

  3. ${Top}

Context

The ${Context} variable contains additional information—relating to currently processed data objects and identifiers for the template—that is used during the processing of the current template. This information provides context for the data that is being processed or rendered.

${Context} contains three variables:

Count

The total number of results available in the current data object being processed within a repeater structure. This alters the flow of a repeater element based on the total number of results.

Use: ${Context.Count}

Index

The current numeric index being processed within a repeater structure. Much like the Count variable, Index allows you to alter the flow of the loop based on the current object index processed.

Use: ${Context.Index}

UniqueId

Provides a unique identifier for the current template. This value can be used to generate custom IDs for DOM nodes in the template markup.

Use: ${Context.UniqueId}

Cur

The ${Cur} variable refers ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required