IOrbTemplate Interface

The IOrbTemplate interface is the dynamic template interface, which specifies the render method, which has the following signature.

render(object: Object): Binary;

A class that implements this interface can function as a dynamic template, which can be defined using the addDynamicTemplate method.

When the Orb templating engine would expand an object with a dynamic template, the render method on the associated class is invoked. The expansion object is passed as the object parameter of the render method.

The Binary value returned by the render method becomes the result of expanding the dynamic template; for example, the result of the render method could be the result of a bind method on an HTML template (or another dynamic template).

Take care not to cause recursive dynamic template expansions.

The following is an example of a dynamic template render method.

render(object: Object): Binary;
vars
   item : AgendaItem;
   user : UserAccount;
   info : RatingInfo;
   lite : Boolean;
begin
   item := object.AgendaItem;
   if not Orb@sessionData(user) then
      return Orb@wrap('');
   endif;
   lite := item.isLite();
// lite items can't be rated
   if not lite and user <> null then
      info := item.allRatingsByUser[user]; 
      if info <> null then
         return Orb@bind("agenda/item/rated", item);
      endif;
   endif;
   if not lite then
      return Orb@bind("agenda/item", item);
   else
      return Orb@bind("agenda/item/lite", item);
   endif;
end;

When this template is expanded, the render method is passed the expansion object, which should be an instance of AgendaItem and the result will be one of the following. The user:

This mechanism of using a dynamic template to select between multiple, different HTML templates is a typical use of this feature.