JS Constants
Including Constants
You can include the JS constants by placing constants()
in your <head>
.
{{ constants() }}
Constants are included by default when creating a theme.{.tip}
Available Constants
APPLICATION_URL
The full base URL of the application.
window.location = APPLICATION_URL;
APPLICATION_REFERENCE
The reference of the application defined by environment data.
let log = new XMLHttpRequest();
log.open('GET', REQUEST_ROOT_PATH + '/app/' + APPLICATION_REFERENCE + '/process.log', true);
log.setRequestHeader('Content-Type', 'application/json');
log.send();
APPLICATION_DOMAIN
The domain of the application defined by environment data.
window.location = 'https://' + APPLICATION_DOMAIN;
CSRF_TOKEN
The CSRF token value. This is helpful when sending requests to your application with JS.
let request = new XMLHttpRequest();
request.open('POST', REQUEST_ROOT_PATH + '/example/toggle', true);
request.setRequestHeader('Content-Type', 'application/json');
request.send(JSON.stringify({
_token: CSRF_TOKEN
}));
APP_DEBUG
A boolean flag indicating whether debugging is enabled or not.
if (APP_DEBUG) {
console.log(data);
}
APP_URL
The application URL as defined by configuration.
window.location = APP_URL;
REQUEST_ROOT
The entire request root.
REQUEST_ROOT_PATH
let log = new XMLHttpRequest();
log.open('GET', REQUEST_ROOT_PATH + '/app/' + APPLICATION_REFERENCE + '/process.log', true);
log.setRequestHeader('Content-Type', 'application/json');
log.send();
The request root path.
TIMEZONE
The configured application timezone.
console.log(TIMEZONE); // America/Chicago
LOCALE
The configured application locale.
console.log(LOCALE); // en