Skip to content
Eric edited this page Jan 27, 2024 · 56 revisions

OSE or Ogx Scripting Engine is Javascript with a few twists and added keywords, that you can use in OML and html templates. Here is a basic example

 {{
      loop $images as index image {
           echo <div class="image"><span class="increment">&index</span><img src="&image.url" height="&image.height" width="&image.width"></div>;
      }         
 }}

Scripts start with {{ and end with }}. For readability, they are omitted in the rest of this page.

Variables

OSE uses different types of variables. They either start by @ # & $ %.

Variables starting with & refer to the thread's data object.

Variables starting with @ refer to the script's data object.

Variables starting with $ refer to an optional data object.

Variables starting with % refer to the route's data object.

Variables starting with # refer to global variables.

Note that variables have to start with [a-zA-Z_]

Keywords

OSE only contains a few added keywords/methods

  template
  json
  oml
  ose
  crumb
  echo
  uxi
  method
  function
  for cyclable as [index or object or value] [object or value] 
  mongogx
  scope
  screen
  result

template

The template keyword is used to load and return as string, a preloaded HTML template.

  template MyPreloadedTemplate

You can also pass an object to templatize

  template MyPreloadedTemplate SomeObject

json

The json keyword is used to load and return as a preloaded JSON object

  json MyPreloadedJson

oml

The oml keyword is used to load and return as a preloaded OML object

  oml MyPreloadedOml

ose

The ose keyword is used to load and return as a preloaded OSE script

  ose MyPreloadedScript

crumb

The crumb keyword is used to retrieve a property from an object generated from the route-capture. It is equivalent to %

  crumb id

result

The result is to be used to retrieve the result of a Promise, generated by a Function

  result function_id

echo

The echo keyword is used to add to the return buffer, if return is not used, such as

  echo 'hey ';
  /* do some other stuff */
  echo 'ho';

The end of the script would return

  'hey ho'

Same as

   return 'hey ho';

Note that you can omit the quotes when using echo

uxi

The uxi keyword is used to point to a live object.

  uxi uxiID:uxiType

  uxi mySwitch:Switch

method 1.20.0+

The method keyword is used to point to a live object's method.

  method methodName uxiID:uxiType  //Link to method
  method methodName() uxiID:uxiType //Execute method, parameters will be auto

To toggle a Switch using OSE

  method toggle() mySwitch:Switch

function 1.33.0+

Use the function keyword to declare and execute an inline function or call a globally available function

  function MyGlobalFunction //Link to function
  function MyGlobalFunction() //Execute function, parameters will be auto
  function if($color === 'red'){return '#EE3333';} return '#33EE33'; //Inline, declare and execute

loop

The loop keyword is used to loop or cycle over an array or an object. For an array of images as object

  loop $images as image
  loop $images as index image

To loop over the properties of an object

  loop $myobject as property
  loop $myobject as property value

The new variables: image, index, property and value will be accessible starting with &

   echo <div class="image" style="background-image:url(&image.url)"></div>;

All together

  loop $images as index image {
       echo <div class="image"><span class="increment">&index</div><img src="&image.url" height="&image.height" width="&image.width">;
  }  

mongogx

If you use MongOGX as a local database, you get fetch some data and pass it to any object using OSE, such as

  mongogx.DB.COL.find(QUERY)

A concrete example

  mongogx.my_project.users.find({});

scope

You can also test the scope of the app, and use another OSE script as a result of this condition

 scope admin manager ? template Manager : template Employee 
 scope admin manager ? #company.revenue : null
 ...

screen

You can also test the screen width of the app, and use another OSE script as a result of this condition

 screen > 500 ? template Big : template Small

callbacks

You can also use a callback and pass the local object $, thread object & or the temporary object @, such as

 myCallBack($)

Mixing commands

You can of course mix commands, for instance, to retrieve a file dynamically

 {{template $mytemplate}} //will get the template that $mytemplate resolves to
 {{json $myjson.someproperty}} //will get a jso document that $myjson resolves to then returns the prop/value
 {{ose myotherscript}} //include another script

Of course you can set variables and use standard javascript

 {{
      @mytempvar = json myfile.mylist;
      let somevar = 'some var';
      loop @mytempvar as index object{
           echo <span>&object.name</span>; 
      }
      return somevar;  
 }}