The source code inside blocks are treated as templates which get preprocessed before passing to the host language interpreter.
Inside templates users are able to use control flow constructs, like loops and conditions and interpolation expressions. Interpolation expressions within templates are evaluated and their string representation is automatically inserted at the position. If an interpolation expression evaluates to null
an empty string is added.
Expressions
Expressions insert value of the CoginitiScript expression into a final code. {{
and }}
delimiters are used to insert an expression into a template code.
Examples:
{{ 1 + 1 }} {{ "string" }} {{ i > 5 }} {{ variable_name }}
Conditions
Conditions allows to execute arbitrary piece of code based on condition. It is defined using #+if
statement.
#+if debug == true then SELECT ...; #+end
You can also use IF...ELSE...END
constructs.
#+if debug == true then SELECT ...; #+else SELECT ....; #+end
Loops
Provides ability to loop over items in the collection.
#+for el : elements do {{ el }} #+end
It optionally allows to specify what to prepend (BEFORE), put in-between (SEPARATOR), and what to put at the end (AFTER) of all iterations. BEFORE and AFTER are only executed if there is at least one iteration. (SEPARATOR) is only added between iterations. It is executed if there are at least two iterations.
#+src sql queryCustomers(fields) #+begin SELECT #+for f : fields separator "," do {{ el }} #+end FROM customers ; #+end