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 |
|---|---|---|
|
| Less than |
|
| Greater than |
|
| Less than or equal to |
|
| Greater than or equal to |
|
| And |
|
| Equals |
|
| Not equals |
|
| Or |
|
| 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.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access