Tagscript

StopParser

End the render immediately and return a message.

stop ends the render as soon as its expression is true. The payload becomes the output and no tag after it runs. Use it to reject bad input before the rest of the template does any work.

For template authors

Syntax

{stop(expression):message}

Examples

{stop({args}==):You must provide input.}Hello {args}
# when args is empty
You must provide input.
# when args is "Parbez"
Hello Parbez

Aliases

stop, halt, error

For developers

Register the parser

import { Interpreter, StopParser } from 'tagscript';
const ts = new Interpreter(new StopParser());

Behaviour

The parameter is required. The payload is optional and defaults to an empty string.

parse throws an Error carrying the payload. The interpreter catches it, abandons the remaining tags and returns the text rendered so far plus the message. Nothing propagates to your await ts.run(...) call, so you do not need a try block for this.

A stopped render still returns a normal Response. Anything earlier tags wrote to response.actions is still there, so check the actions you care about rather than assuming a stop means "do nothing".

API reference

StopParser

Last updated on

On this page

Edit on Github