Other methods

redirectTo

Description

Stop the rendering of the current page and redirect the user to another Locomotive page. This page is specified by its handle.

Usage

redirectTo(<page handle>, <locale>);

Note: the locale argument is optional.

Example

{% action 'Basic redirection' %}

if (params.confirmed) {
  redirectTo('home');
}

{% endaction %}

Logging

Description

When using actions, you might want to print out some of your requests, responses or simply print out statements, to see if your code is being executed.
The way to do that is by using Duktape's built in class Logger.

const val1 = 'foo';
const val2 = 123;
const val3 = new Date(123456789e3);

const logger = new Duktape.Logger();
logger.info('three values:', val1, val2, val3);
2019-05-15T12:01:54.762Z INF (duktape): three values: foo 123 1973-11-29 22:33:09.000+01:00

For more details about the Logger class you can read the official documentation: [https://wiki.duktape.org/howtologging]