Velocity Context Objects

Velocity  context objects

EduBrite environment provides customisation using Velocity ( Velocity is a Java-based template engine.) 

The Site Page Template, "Imported" (with #import) Site Page Include, and any widgets velocity files (.vm files, for UI rendering) are run through velocity engine. There are  few common objects which are by default available in velocity context. In addition depending on each widgets business logic there will be contextual objects with relevant data available in velocity context.

In velocity variables are accessed by "$" prefix

Here are common object available in context and their usage

UI / UIContext 

Most widely used context object is  UI   accessed in velocity $UI  ( aka UIContext) 

$UI.isGuest() boolean Return true, If is anonyomous user. It returns falses in case of user is logged in.
$UI.isL2AdminSiteAdmin() boolean Returns true if logged in user in Site Admin or EduBrite's support admin
$UI.getCurrentUser().getFirstName() String FirstName
$UI.getCurrentUser().getLastName() String LastName
$UI.getCurrentUser().getEmail() String Email
$UI.getCurrentUser().getStatus() String Value could be ACTIVE / INACTIVE
$UI.getUrl() String Current URL
$UI.getQueryString() String Query String
$UI.getSite().getName() String Current Site's name
$UI.getUserAgent() String Http user agent string
$UI.getReferrer() String Referrer url
$UI.getCurrentTimezone() String Returns current site timezone code exmaple : GMT / PST
$UI.getCaption(String Key) String - Key defined in site placements custom label Returns i18N string value of as defined in site

 

Common helper Classes / Objects 

Other commonly used utilities (objects and classes) available are 

  • $numberTool  =>    Velocity's NumberTool object ( Read more )
  • $math  =>  Velocity's MathTool object  ( Read more)

  • $escTool  =>  Velocity's  EscapeTool object ( Read more)

  • $JsonHelper     => class reference of EduBrite's Json Helper with following static helper methods for json handling

$JsonHelper.safePutObj(String key, Object val, JSONObject obj) Puts object "val" in JSONObject obj with key "key"
$JsonHelper.safeGetObj(String key, JSONObject obj) Gets object from JSONObject obj with key "key"
$JsonHelper.safePutInArr(JSONArray arr, Object val) Puts object "val" in JSONArray arr
$JsonHelper.safeGetArray(String key, JSONObject obj) Gets JSONArray from JSONObject obj with key "key"
$JsonHelper.safeGetStr(String key, JSONObject obj) Gets String from JSONObject obj with key "key"
$JsonHelper.safeGetFloat(String key, JSONObject obj) Gets Float from JSONObject obj with key "key"
$JsonHelper.safeGetInteger(String key, JSONObject obj) Gets Integer from JSONObject obj with key "key"
$JsonHelper.fullySafeGetBoolean(String key, JSONObject obj) Gets Boolean from JSONObject obj with key "key"
$JsonHelper.createJSONObject(String objStr) Create Json object from a valid json string
$JsonHelper.deepMerge(JSONObject source, JSONObject target) Merge "source" into "target". If fields have equal name, merge them recursively.

 


Rating: