company logo

OSI templates

OSI templates are a specific way of defining a function. Usually, OSI templates are used, when having a sort of text template, which is to be filled with data from the database.

Since one can use the SystemClass::WriteResult() or FileHandle::Out() functions in a OSI function, template functions are not really required, but are useful in many cases. In contrast to OSI functions, template functions are easier to read and easier to write.

OSI templates support conditional text generation as well as embedded OSI expressions. One may call templates from within a template etc. The template result will be generated as templates are called. Since one may access the template result at any time, it is possible to update the generated result during the generation process.

OSI templates can be considered as inverse functions, but there are some restrictions compared with functions. The example below shows a way of converting an OSI template into an OSI function. Since templates are just a simplified way of defining text functions, one may also mix templates and OSI functions or create a template result just by calling OSI functions.

Details for OSI template syntax are described in the Reference Documentation OSI Template syntax.

$template string Test()$

Dear $if (sex == "male")$Mr. $else$Mrs. $end$ $family_name$,

We just got your question concerning $product$, which you are using since $buing_date$. We have forwarded your problem to $responsible(0).first_name$\ $responsible(0).second_name$.

You will get an response during the next three days.

...

$return TemplateString$

$end$

// same template expressed as OSI function

function string Test () {

  WriteResult("Dear ",false);

  if (sex == "male") WriteResult("Mr. ",false);

  else WriteResult("Mrs. ",false);

  WriteResult(family_name,false);

  WriteResult(",",false);

  WriteResult("We just got your question concerning ",false);

  WriteResult(product,false);

  WriteResult("which you are using since ",false);

  WriteResult(buing_date,false);

  WriteResult(".",false);

  WriteResult("We have forwarded your problem to ",false);

  WriteResult(responsible(0).first_name,false);

  WriteResult(" ",false);

  WriteResult(responsible(0).second_name,false);

  WriteResult("You will get an response during the next three days. \n...\n",false);

  return TemplateString;

}

Related topics