Create an if statement to tell an application what to do if a certain condition exists:
if(date.hours(date.now) >= 12) { template("Custom/Views/Header"); }
Output: INTENTIONALLY NOT RENDERED
Display text for admin users when they visit a page, but display different text for non-admin users:
if (user.name == "Admin") { "This information can only be seen by the admin. No other use user can see it."; } else { "If you do not want non-admin users to see anything, just do not type anything between the quotation marks."; }
Make sure that the "a" in Admin is capitalized.
For DekiScript to ignore case, create a variable for user.name
and add string.tolower
before the variable as in the following example:
var luser = string.tolower(user.name); if (luser == "admin") { "Hello, admin."; } else { "You are not an admin."; }
Evaluate a conditional expression, if the outcome of the expression is nil, false or 0, execute the block immediately following the if statement. Otherwise, execute the block following the optional else statement.
Different languages treat different values that are not a true/false boolean differently. In DekiScript false as well as nil and zero are logically false, while True and everything else (other than nil, false or 0) are treated as logically true.
To conditionally include a template:
if(date.hours(date.now) >= 12) { template("Custom/Views/Header"); }
Output: INTENTIONALLY NOT RENDERED
To conditionally emit one text or another:
if(user.anonymous) { "Welcome guest. Please register!" } else { "Welcome back ".. user.name .. "!" }
Output: Welcome guest. Please register!
Telling an application what to do if something does NOT equal something:
var x =25; if (user.name != "Admin") { let x = 75; } x;
In DekiScript false
as well as nil
and zero
are logically false, while true
and everything else (other than nil, false or 0) are treated as logically true.