Expressions

In the context of OpenSocial templates, expression refers to an evaluation of some data source that is embedded directly into a markup structure.

Expressions can be rendered in a template using a simple syntax:

${Expression}

Expressions may be embedded inside text nodes and attributes, but will not be honored by an implementing container if they are inside custom tags and attribute names—a subject we will explore later in this chapter.

In addition to basic data rendering, most standard arithmetic expressions and data comparison features can be applied to expressions:

Next Index: ${Index + 1}

The functionality of these expressions is based on a modified version of the JSP expression language. Even though there are definitions for these arithmetic and comparison features, some operators use an XML escaped alternative for comparisons, such as when implementing OpenSocial template os:If statements. These escaped versions are listed in Table 7-7.

Table 7-7. Escaped versions of comparison operators

Conditional

Escaped string

Description

<

lt

Less than

>

gt

Greater than

<=

lte

Less than or equal to

>=

gte

Greater than or equal to

&&

and

And

==

eq

Equals

!=

neq

Not equals

||

or

Or

!

not

Not

By default, expressions are evaluated as escaped strings before they are inserted into the HTML document. Expressions are the basis for the majority of what we do with OpenSocial templates, so it’s crucial that you have a basic understanding of them.

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.