Built-In Keywords
Keywords are named constants within a scripting context.
Usage
If the value of a constant is an object, its contents can be dereferenced using dot notation.
Most keywords can be used in JavaScript and StructrScript contexts. In a StructrScript context, they can be used directly. In a JavaScript context the can be used via the $.get(<keyword>)
function (or since release 3.5 also via $.<keyword>
).
JavaScript-only keywords are made available by functions.
StructrScript Example
${page.name}
${current.owner.name}
JavaScript Example (< 3.5)
${{ $.print($.get('page').name); }}
${{ $.print($.get('current').owner.name); }}
JavaScript Example (>= 3.5)
${{ $.print($.get('page').name); }}
${{ $.print($.page.name); }}
${{ $.print($.current.owner.name); }}
Keyword List
keyboard_arrow_rightkeyboard_arrow_downbase_url
The base_url
(alternatively baseUrl
) keyword returns the base URL for the application. The value is assembled from the protocol, hostname and port of the server instance Structr is running on.
It produces http(s)://<host>(:<port>)
depending on the configuration.
Notes
If
application.baseurl.override
is set in structr.conf, this value will be returned.If HTTPS is enabled this will always begin with https://
If this keyword is used in a script called without a request (e.g. a CRON job), the configuration keys
application.host
andapplication.http.port
(orapplication.https.port
) are returned. If a request is available, the information will be taken from there.
Examples
${base_url}
https://foo.bar:1234
keyboard_arrow_rightkeyboard_arrow_downchildren
The children keyword returns the child nodes of the current node.
Notes
This keyword is only available on Page Elements (DOM nodes).
Examples
${render(children)}
keyboard_arrow_rightkeyboard_arrow_downcurrent
The current keyword returns the object returned by URI Object Resolution, if available.
keyboard_arrow_rightkeyboard_arrow_downdata
The data
keyword returns the current element in an each()
loop iteration or in a filter()
expression.
keyboard_arrow_rightkeyboard_arrow_downhost
The host
keyword returns the host name of the server to which the request was sent.
It is the value of the part before “:” in the Host header value, if any, or the resolved server name, or the server IP address.
keyboard_arrow_rightkeyboard_arrow_downid
The id
keyword returns the id of the object returned by URI Object Resolution, if available.
keyboard_arrow_rightkeyboard_arrow_downip
Available from v3.6:
The ip
keyword returns the Internet Protocol (IP) address of the interface on which the request was received.
Notes
Only available in a context where structr is responding to a request
keyboard_arrow_rightkeyboard_arrow_downinput
The input
keyword returns the current object (of the Virtual Type) when used in a VirtualProperty context.
Notes
This keyword is only available in a virtual type context.
keyboard_arrow_rightkeyboard_arrow_downlink
The link
keyword references the linked node of an element.
Only works in a
, link
, script
or img
tags/nodes. See Filesystem and Pages Tree View for more info.
The link
keyword can only be accessed if a node of the above types is actually linked to a filesystem element. It can be linked via the link icon which is displayed when hovering over a node.
keyboard_arrow_rightkeyboard_arrow_downlocale
The locale
keyword returns the current locale. It is determined like this in descending priority:
- Request parameter
locale
- User locale
- Cookie
locale
- Browser locale
- Default locale which was used to start the java process (evaluated via
java.util.Locale.getDefault();
)
keyboard_arrow_rightkeyboard_arrow_downme
The keyword me
contains a reference to the current user.
The keyword can be used in all Template Expressions, in Hide and show Conditions etc. It is often used to show/hide individual parts of a page depending on the permissions / status of a user etc.
Notes
In an anonymous context, the
me
keyword returns an empty resultIn a privileged context, the
me
keyword returns the SuperUser - working with this is discouraged/impossible.
Examples
Hello ${me.name}!
Hello admin!
keyboard_arrow_rightkeyboard_arrow_downpage
The page
keyword returns the page object currently being rendered.
Notes
This keyword is only available in a page context.
Examples
${page.name}
Used in the page URL = https://localhost:8082/people?sort=lastName&order=asc
people
keyboard_arrow_rightkeyboard_arrow_downparameter_map
The parameter_map
returns a map (String, String) containing all request parameters of the current request.
parameterMap
is an alias for this keyword.
Notes
The values for each GET parameter are always arrays as they can occurr more than once.
Examples
${parameter_map}
(1) Used in the page URL = https://localhost:8082/people?sort=lastName&order=asc
(2) Used in the page URL = https://localhost:8082/people?sort=lastName&sort=firstName&order=asc
(1) {sort=[lastName],order=[asc]}
(2) {sort=[lastName, firstName],order=[asc]}
keyboard_arrow_rightkeyboard_arrow_downpath_info
The path_info
returns any extra path information associated with the URL the client sent when it made this request.
The extra path information follows the servlet path but precedes the query string and will start with a “/” character.
pathInfo
is an alias for this keyword.
keyboard_arrow_rightkeyboard_arrow_downport
The port
keyword returns the port number to which the request was sent.
It is the value of the part after “:” in the Host header value, if any, or the server port where the client connection was accepted on.
keyboard_arrow_rightkeyboard_arrow_downquery_string
The query_string
returns the complete query string of the current request.
queryString
is an alias for this keyword.
Examples
Used in the page URL = https://localhost:8082/people?sort=lastName&sort=firstName&order=asc
${query_string}
sort=lastName&sort=firstName&order=asc
keyboard_arrow_rightkeyboard_arrow_downrequest
The request
keyword returns a reference to the current HTTP request object (see javax.servlet.http.HttpServletRequest). It can be used to access HTTP GET request parameters.
Notes
To access values in the body of an HTTP POST request, please use the
retrieve()
function.If you are running methods from a Cron job, the request object is null, so if you are using that method in another context where you want to supply request parameters, in order for it to stay error-free in the Cron context, you need to null-check the request.
If a GET parameter occurs multiple times it will be made available as an array. If it is only present once, the value will be returned.
Examples
(1) Used in the page URL = https://localhost:8082/people?sort=lastName&order=asc
${request.sort}
(2) Used in the page URL = https://localhost:8082/people?sort=firstName&sort=lastName&order=asc
${first(request.sort)}
(1) lastName
(2) firstName
keyboard_arrow_rightkeyboard_arrow_downremote_address
The remote_address
keyword returns the IP from which the current request originated.
Examples
${remote_address}
127.0.0.1
keyboard_arrow_rightkeyboard_arrow_downresponse
The response
keyword returns a reference to the current output stream of the HTTP response that is sent to the client when the rendering process is finished.
The response
keyword can be used in the special functions create_jar_file()
and exec_binary()
to allow direct streaming of binary data from a StructrScript to the client.
keyboard_arrow_rightkeyboard_arrow_downstatus_code
The status_code
returns the HTTP status code for the current response.
statusCode
is an alias for this keyword.
keyboard_arrow_rightkeyboard_arrow_downtemplate
The template
keyword returns the Template element closest to the current element in the page tree.
Notes
This keyword is only available on Page Elements (DOM nodes).
keyboard_arrow_rightkeyboard_arrow_downtenant_identifier
The tenant_identifier
keyword returns the tenant identifier from structr.conf (database.tenant.identifier
).
tenantIdentifier
is an alias for this keyword.
keyboard_arrow_rightkeyboard_arrow_downvalue
The value
keyword returns the value passed to the write function of a FunctionProperty.
Notes
This keyword is only available in the context of a write function of a FunctionProperty.
JavaScript-only keywords
The following keywords are only directly usable in JavaScript. See Keyword Helper Functions to see how to use this can be used in StructrScript.
keyboard_arrow_rightkeyboard_arrow_downapplicationStore
Can be used to store data in-memory as long as the instance is running. The applicationStore can be accessed like a simple JavaScript object and can store arbitrary things.
Notes
Keyword was introduced in v4.0-SNAPSHOT and is not available in 3.x releases
Do not use this to store nodes/relationships.
Be aware that this consumes memory - storing big amounts of data is not recommended.
Examples
${{
if (!$.applicationStore['code_was_run']) {
$.log('running some code only once...');
$.applicationStore['code_was_run'] = true;
}
}}
keyboard_arrow_rightkeyboard_arrow_downmethodParameters
Returns all method parameters in schema methods as a map.
Notes
Keyword was introduced in v4.0-SNAPSHOT and is not available in 3.x releases
Examples
{
$.log($.methodParameters.param1);
$.log($.methodParameters['param1']);
}
keyboard_arrow_rightkeyboard_arrow_downrequestStore
Can be used to store data in-memory for the duration of the current request. The requestStore can be accessed like a simple JavaScript object and can store arbitrary things.
This keywords uses the same data store as the $.store() and $.retrieve() functions but is easier to use in JavaScript. The newer set of helper functions for this keyword is preferred versus store() and retrieve().
Notes
Keyword was introduced in v4.0-SNAPSHOT and is not available in 3.x releases
Do not use this to store nodes/relationships.
Be aware that this consumes memory - storing big amounts of data is not recommended.
Examples
{
for (let cnt = 0; cnt < 10; cnt++) {
$.log(cnt);
if (!$.requestStore['code_was_run']) {
$.log('running some code only once per request...');
$.requestStore['code_was_run'] = true;
}
}
}