Other Special Tags

In addition to the special tags we have already seen, os:Repeat and os:If, OpenSocial templates define a couple of reserved tags to enable developers to display data objects that are richer than simple strings. These special tags are os:Html and os:Render.

os:Html

When rendering data within escaped expressions or loops (i.e., not os:Repeat or os:If blocks), developers run into the issue that because all data is displayed as strings, they’re prevented from using a lot of rich data sets. When you’re using third-party data sources that are not necessarily trusted, this practice is a good option for sanitizing content. When a part of the source data is trusted, however, we need a means of rendering that data with the markup intact. This is where the os:Html tag comes in handy.

os:Html provides a means for a developer to render a block of data without having it automatically escaped and displayed as a string. The markup is rendered intact and applied to the template.

You use os:Html through the code attribute of the tag. Any data values within the code attribute are evaluated as a string and then rendered as HTML. For instance, if you have an object containing the viewer’s friends, and in that object you also have a name and a badge that contains HTML, you can easily render the badge HTML using the os:Html tag as follows:

<div repeat="${Top.ViewerFriends}">
   Name: ${Cur.name}<br />
   Badge:<br />
   <os:Html code="${Cur.badge}" />
</div>

Once rendered, name will be displayed as ...

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.